1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
9 #include "base/auto_reset.h"
10 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "base/callback_helpers.h"
13 #include "base/command_line.h"
14 #include "base/logging.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/trace_event/trace_event.h"
18 #include "cc/layers/layer.h"
19 #include "cc/output/copy_output_request.h"
20 #include "cc/output/copy_output_result.h"
21 #include "cc/resources/texture_mailbox.h"
22 #include "cc/trees/layer_tree_settings.h"
23 #include "content/browser/accessibility/browser_accessibility_manager.h"
24 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
25 #include "content/browser/bad_message.h"
26 #include "content/browser/frame_host/frame_tree.h"
27 #include "content/browser/frame_host/frame_tree_node.h"
28 #include "content/browser/frame_host/render_frame_host_impl.h"
29 #include "content/browser/gpu/compositor_util.h"
30 #include "content/browser/renderer_host/compositor_resize_lock_aura.h"
31 #include "content/browser/renderer_host/dip_util.h"
32 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h"
33 #include "content/browser/renderer_host/input/touch_selection_controller_client_aura.h"
34 #include "content/browser/renderer_host/input/ui_touch_selection_helper.h"
35 #include "content/browser/renderer_host/input/web_input_event_util.h"
36 #include "content/browser/renderer_host/overscroll_controller.h"
37 #include "content/browser/renderer_host/render_view_host_delegate.h"
38 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
39 #include "content/browser/renderer_host/render_view_host_impl.h"
40 #include "content/browser/renderer_host/render_widget_host_delegate.h"
41 #include "content/browser/renderer_host/render_widget_host_impl.h"
42 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
43 #include "content/browser/renderer_host/ui_events_helper.h"
44 #include "content/browser/renderer_host/web_input_event_aura.h"
45 #include "content/common/gpu/client/gl_helper.h"
46 #include "content/common/gpu/gpu_messages.h"
47 #include "content/common/view_messages.h"
48 #include "content/public/browser/content_browser_client.h"
49 #include "content/public/browser/overscroll_configuration.h"
50 #include "content/public/browser/render_view_host.h"
51 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
52 #include "content/public/browser/user_metrics.h"
53 #include "content/public/common/content_switches.h"
54 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
55 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
56 #include "third_party/WebKit/public/web/WebInputEvent.h"
57 #include "ui/aura/client/aura_constants.h"
58 #include "ui/aura/client/cursor_client.h"
59 #include "ui/aura/client/cursor_client_observer.h"
60 #include "ui/aura/client/focus_client.h"
61 #include "ui/aura/client/screen_position_client.h"
62 #include "ui/aura/client/window_tree_client.h"
63 #include "ui/aura/env.h"
64 #include "ui/aura/window.h"
65 #include "ui/aura/window_event_dispatcher.h"
66 #include "ui/aura/window_observer.h"
67 #include "ui/aura/window_tracker.h"
68 #include "ui/aura/window_tree_host.h"
69 #include "ui/base/clipboard/scoped_clipboard_writer.h"
70 #include "ui/base/hit_test.h"
71 #include "ui/base/ime/input_method.h"
72 #include "ui/base/ui_base_types.h"
73 #include "ui/compositor/compositor_vsync_manager.h"
74 #include "ui/compositor/dip_util.h"
75 #include "ui/events/blink/blink_event_util.h"
76 #include "ui/events/event.h"
77 #include "ui/events/event_utils.h"
78 #include "ui/events/gesture_detection/gesture_configuration.h"
79 #include "ui/events/gestures/gesture_recognizer.h"
80 #include "ui/gfx/canvas.h"
81 #include "ui/gfx/color_profile.h"
82 #include "ui/gfx/display.h"
83 #include "ui/gfx/geometry/rect_conversions.h"
84 #include "ui/gfx/geometry/size_conversions.h"
85 #include "ui/gfx/screen.h"
86 #include "ui/gfx/skia_util.h"
87 #include "ui/touch_selection/touch_selection_controller.h"
88 #include "ui/wm/public/activation_client.h"
89 #include "ui/wm/public/scoped_tooltip_disabler.h"
90 #include "ui/wm/public/tooltip_client.h"
91 #include "ui/wm/public/transient_window_client.h"
92 #include "ui/wm/public/window_types.h"
95 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
96 #include "content/browser/accessibility/browser_accessibility_win.h"
97 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
98 #include "content/common/plugin_constants_win.h"
99 #include "ui/base/win/hidden_window.h"
100 #include "ui/gfx/gdi_util.h"
101 #include "ui/gfx/win/dpi.h"
104 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
105 #include "content/common/input_messages.h"
106 #include "ui/events/linux/text_edit_command_auralinux.h"
107 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
110 using gfx::RectToSkIRect
;
111 using gfx::SkIRectToRect
;
113 using blink::WebScreenInfo
;
114 using blink::WebInputEvent
;
115 using blink::WebGestureEvent
;
116 using blink::WebTouchEvent
;
122 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting
123 // the border of the view, in order to get valid movement information. However,
124 // forcing the cursor back to the center of the view after each mouse move
125 // doesn't work well. It reduces the frequency of useful mouse move messages
126 // significantly. Therefore, we move the cursor to the center of the view only
127 // if it approaches the border. |kMouseLockBorderPercentage| specifies the width
128 // of the border area, in percentage of the corresponding dimension.
129 const int kMouseLockBorderPercentage
= 15;
131 // When accelerated compositing is enabled and a widget resize is pending,
132 // we delay further resizes of the UI. The following constant is the maximum
133 // length of time that we should delay further UI resizes while waiting for a
134 // resized frame from a renderer.
135 const int kResizeLockTimeoutMs
= 67;
138 // Used to associate a plugin HWND with its RenderWidgetHostViewAura instance.
139 const wchar_t kWidgetOwnerProperty
[] = L
"RenderWidgetHostViewAuraOwner";
141 BOOL CALLBACK
WindowDestroyingCallback(HWND window
, LPARAM param
) {
142 RenderWidgetHostViewAura
* widget
=
143 reinterpret_cast<RenderWidgetHostViewAura
*>(param
);
144 if (GetProp(window
, kWidgetOwnerProperty
) == widget
) {
145 // Properties set on HWNDs must be removed to avoid leaks.
146 RemoveProp(window
, kWidgetOwnerProperty
);
147 RenderWidgetHostViewBase::DetachPluginWindowsCallback(window
);
152 BOOL CALLBACK
HideWindowsCallback(HWND window
, LPARAM param
) {
153 RenderWidgetHostViewAura
* widget
=
154 reinterpret_cast<RenderWidgetHostViewAura
*>(param
);
155 if (GetProp(window
, kWidgetOwnerProperty
) == widget
)
156 SetParent(window
, ui::GetHiddenWindow());
160 BOOL CALLBACK
ShowWindowsCallback(HWND window
, LPARAM param
) {
161 RenderWidgetHostViewAura
* widget
=
162 reinterpret_cast<RenderWidgetHostViewAura
*>(param
);
164 if (GetProp(window
, kWidgetOwnerProperty
) == widget
&&
165 widget
->GetNativeView()->GetHost()) {
166 HWND parent
= widget
->GetNativeView()->GetHost()->GetAcceleratedWidget();
167 SetParent(window
, parent
);
172 struct CutoutRectsParams
{
173 RenderWidgetHostViewAura
* widget
;
174 std::vector
<gfx::Rect
> cutout_rects
;
175 std::map
<HWND
, WebPluginGeometry
>* geometry
;
178 // Used to update the region for the windowed plugin to draw in. We start with
179 // the clip rect from the renderer, then remove the cutout rects from the
180 // renderer, and then remove the transient windows from the root window and the
181 // constrained windows from the parent window.
182 BOOL CALLBACK
SetCutoutRectsCallback(HWND window
, LPARAM param
) {
183 CutoutRectsParams
* params
= reinterpret_cast<CutoutRectsParams
*>(param
);
185 if (GetProp(window
, kWidgetOwnerProperty
) == params
->widget
) {
186 // First calculate the offset of this plugin from the root window, since
187 // the cutouts are relative to the root window.
189 params
->widget
->GetNativeView()->GetHost()->GetAcceleratedWidget();
191 offset
.x
= offset
.y
= 0;
192 MapWindowPoints(window
, parent
, &offset
, 1);
194 // Now get the cached clip rect and cutouts for this plugin window that came
195 // from the renderer.
196 std::map
<HWND
, WebPluginGeometry
>::iterator i
= params
->geometry
->begin();
197 while (i
!= params
->geometry
->end() &&
198 i
->second
.window
!= window
&&
199 GetParent(i
->second
.window
) != window
) {
203 if (i
== params
->geometry
->end()) {
208 HRGN hrgn
= CreateRectRgn(i
->second
.clip_rect
.x(),
209 i
->second
.clip_rect
.y(),
210 i
->second
.clip_rect
.right(),
211 i
->second
.clip_rect
.bottom());
212 // We start with the cutout rects that came from the renderer, then add the
213 // ones that came from transient and constrained windows.
214 std::vector
<gfx::Rect
> cutout_rects
= i
->second
.cutout_rects
;
215 for (size_t i
= 0; i
< params
->cutout_rects
.size(); ++i
) {
216 gfx::Rect offset_cutout
= params
->cutout_rects
[i
];
217 offset_cutout
.Offset(-offset
.x
, -offset
.y
);
218 cutout_rects
.push_back(offset_cutout
);
220 gfx::SubtractRectanglesFromRegion(hrgn
, cutout_rects
);
221 // If we don't have any cutout rects then no point in messing with the
223 if (cutout_rects
.size())
224 SetWindowRgn(window
, hrgn
, TRUE
);
229 // A callback function for EnumThreadWindows to enumerate and dismiss
230 // any owned popup windows.
231 BOOL CALLBACK
DismissOwnedPopups(HWND window
, LPARAM arg
) {
232 const HWND toplevel_hwnd
= reinterpret_cast<HWND
>(arg
);
234 if (::IsWindowVisible(window
)) {
235 const HWND owner
= ::GetWindow(window
, GW_OWNER
);
236 if (toplevel_hwnd
== owner
) {
237 ::PostMessage(window
, WM_CANCELMODE
, 0, 0);
245 // We don't mark these as handled so that they're sent back to the
246 // DefWindowProc so it can generate WM_APPCOMMAND as necessary.
247 bool IsXButtonUpEvent(const ui::MouseEvent
* event
) {
249 switch (event
->native_event().message
) {
258 void GetScreenInfoForWindow(WebScreenInfo
* results
, aura::Window
* window
) {
259 const gfx::Display display
= window
?
260 gfx::Screen::GetScreenFor(window
)->GetDisplayNearestWindow(window
) :
261 gfx::Screen::GetScreenFor(window
)->GetPrimaryDisplay();
262 results
->rect
= display
.bounds();
263 results
->availableRect
= display
.work_area();
264 // TODO(derat|oshima): Don't hardcode this. Get this from display object.
266 results
->depthPerComponent
= 8;
267 results
->deviceScaleFactor
= display
.device_scale_factor();
269 // The Display rotation and the WebScreenInfo orientation are not the same
270 // angle. The former is the physical display rotation while the later is the
271 // rotation required by the content to be shown properly on the screen, in
272 // other words, relative to the physical display.
273 results
->orientationAngle
= display
.RotationAsDegree();
274 if (results
->orientationAngle
== 90)
275 results
->orientationAngle
= 270;
276 else if (results
->orientationAngle
== 270)
277 results
->orientationAngle
= 90;
279 results
->orientationType
=
280 RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display
);
283 bool IsFractionalScaleFactor(float scale_factor
) {
284 return (scale_factor
- static_cast<int>(scale_factor
)) > 0;
287 // Reset unchanged touch point to StateStationary for touchmove and
289 void MarkUnchangedTouchPointsAsStationary(
290 blink::WebTouchEvent
* event
,
291 int changed_touch_id
) {
292 if (event
->type
== blink::WebInputEvent::TouchMove
||
293 event
->type
== blink::WebInputEvent::TouchCancel
) {
294 for (size_t i
= 0; i
< event
->touchesLength
; ++i
) {
295 if (event
->touches
[i
].id
!= changed_touch_id
)
296 event
->touches
[i
].state
= blink::WebTouchPoint::StateStationary
;
303 // We need to watch for mouse events outside a Web Popup or its parent
304 // and dismiss the popup for certain events.
305 class RenderWidgetHostViewAura::EventFilterForPopupExit
306 : public ui::EventHandler
{
308 explicit EventFilterForPopupExit(RenderWidgetHostViewAura
* rwhva
)
311 aura::Env::GetInstance()->AddPreTargetHandler(this);
314 ~EventFilterForPopupExit() override
{
315 aura::Env::GetInstance()->RemovePreTargetHandler(this);
318 // Overridden from ui::EventHandler
319 void OnMouseEvent(ui::MouseEvent
* event
) override
{
320 rwhva_
->ApplyEventFilterForPopupExit(event
);
323 void OnTouchEvent(ui::TouchEvent
* event
) override
{
324 rwhva_
->ApplyEventFilterForPopupExit(event
);
328 RenderWidgetHostViewAura
* rwhva_
;
330 DISALLOW_COPY_AND_ASSIGN(EventFilterForPopupExit
);
333 void RenderWidgetHostViewAura::ApplyEventFilterForPopupExit(
334 ui::LocatedEvent
* event
) {
335 if (in_shutdown_
|| is_fullscreen_
|| !event
->target())
338 if (event
->type() != ui::ET_MOUSE_PRESSED
&&
339 event
->type() != ui::ET_TOUCH_PRESSED
) {
343 aura::Window
* target
= static_cast<aura::Window
*>(event
->target());
344 if (target
!= window_
&&
345 (!popup_parent_host_view_
||
346 target
!= popup_parent_host_view_
->window_
)) {
347 // If we enter this code path it means that we did not receive any focus
348 // lost notifications for the popup window. Ensure that blink is aware
349 // of the fact that focus was lost for the host window by sending a Blur
350 // notification. We also set a flag in the view indicating that we need
351 // to force a Focus notification on the next mouse down.
352 if (popup_parent_host_view_
&& popup_parent_host_view_
->host_
) {
353 popup_parent_host_view_
->set_focus_on_mouse_down_
= true;
354 popup_parent_host_view_
->host_
->Blur();
356 // Note: popup_parent_host_view_ may be NULL when there are multiple
357 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup().
362 // We have to implement the WindowObserver interface on a separate object
363 // because clang doesn't like implementing multiple interfaces that have
364 // methods with the same name. This object is owned by the
365 // RenderWidgetHostViewAura.
366 class RenderWidgetHostViewAura::WindowObserver
: public aura::WindowObserver
{
368 explicit WindowObserver(RenderWidgetHostViewAura
* view
)
370 view_
->window_
->AddObserver(this);
373 ~WindowObserver() override
{ view_
->window_
->RemoveObserver(this); }
375 // Overridden from aura::WindowObserver:
376 void OnWindowAddedToRootWindow(aura::Window
* window
) override
{
377 if (window
== view_
->window_
)
378 view_
->AddedToRootWindow();
381 void OnWindowRemovingFromRootWindow(aura::Window
* window
,
382 aura::Window
* new_root
) override
{
383 if (window
== view_
->window_
)
384 view_
->RemovingFromRootWindow();
387 void OnWindowHierarchyChanged(const HierarchyChangeParams
& params
) override
{
388 view_
->ParentHierarchyChanged();
392 RenderWidgetHostViewAura
* view_
;
394 DISALLOW_COPY_AND_ASSIGN(WindowObserver
);
397 // This class provides functionality to observe the ancestors of the RWHVA for
398 // bounds changes. This is done to snap the RWHVA window to a pixel boundary,
399 // which could change when the bounds relative to the root changes.
400 // An example where this happens is below:-
401 // The fast resize code path for bookmarks where in the parent of RWHVA which
402 // is WCV has its bounds changed before the bookmark is hidden. This results in
403 // the traditional bounds change notification for the WCV reporting the old
404 // bounds as the bookmark is still around. Observing all the ancestors of the
405 // RWHVA window enables us to know when the bounds of the window relative to
406 // root changes and allows us to snap accordingly.
407 class RenderWidgetHostViewAura::WindowAncestorObserver
408 : public aura::WindowObserver
{
410 explicit WindowAncestorObserver(RenderWidgetHostViewAura
* view
)
412 aura::Window
* parent
= view_
->window_
->parent();
414 parent
->AddObserver(this);
415 ancestors_
.insert(parent
);
416 parent
= parent
->parent();
420 ~WindowAncestorObserver() override
{
421 RemoveAncestorObservers();
424 void OnWindowBoundsChanged(aura::Window
* window
,
425 const gfx::Rect
& old_bounds
,
426 const gfx::Rect
& new_bounds
) override
{
427 DCHECK(ancestors_
.find(window
) != ancestors_
.end());
428 if (new_bounds
.origin() != old_bounds
.origin())
429 view_
->HandleParentBoundsChanged();
433 void RemoveAncestorObservers() {
434 for (auto ancestor
: ancestors_
)
435 ancestor
->RemoveObserver(this);
439 RenderWidgetHostViewAura
* view_
;
440 std::set
<aura::Window
*> ancestors_
;
442 DISALLOW_COPY_AND_ASSIGN(WindowAncestorObserver
);
445 ////////////////////////////////////////////////////////////////////////////////
446 // RenderWidgetHostViewAura, public:
448 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost
* host
,
449 bool is_guest_view_hack
)
450 : host_(RenderWidgetHostImpl::From(host
)),
451 window_(new aura::Window(this)),
452 delegated_frame_host_(new DelegatedFrameHost(this)),
454 in_bounds_changed_(false),
455 is_fullscreen_(false),
456 popup_parent_host_view_(NULL
),
457 popup_child_host_view_(NULL
),
459 text_input_type_(ui::TEXT_INPUT_TYPE_NONE
),
460 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT
),
461 text_input_flags_(0),
462 can_compose_inline_(true),
463 has_composition_text_(false),
464 accept_return_character_(false),
465 last_swapped_software_frame_scale_factor_(1.f
),
467 synthetic_move_sent_(false),
468 cursor_visibility_state_in_renderer_(UNKNOWN
),
470 legacy_render_widget_host_HWND_(NULL
),
471 legacy_window_destroyed_(false),
472 showing_context_menu_(false),
474 has_snapped_to_boundary_(false),
475 is_guest_view_hack_(is_guest_view_hack
),
476 begin_frame_observer_proxy_(this),
477 set_focus_on_mouse_down_(false),
478 weak_ptr_factory_(this) {
479 if (!is_guest_view_hack_
)
480 host_
->SetView(this);
482 window_observer_
.reset(new WindowObserver(this));
484 aura::client::SetTooltipText(window_
, &tooltip_
);
485 aura::client::SetActivationDelegate(window_
, this);
486 aura::client::SetFocusChangeObserver(window_
, this);
487 window_
->set_layer_owner_delegate(delegated_frame_host_
.get());
488 gfx::Screen::GetScreenFor(window_
)->AddObserver(this);
490 // Let the page-level input event router know about our surface ID
491 // namespace for surface-based hit testing.
492 if (UseSurfacesEnabled() && host_
->delegate() &&
493 host_
->delegate()->GetInputEventRouter()) {
494 host_
->delegate()->GetInputEventRouter()->AddSurfaceIdNamespaceOwner(
495 GetSurfaceIdNamespace(), this);
498 bool overscroll_enabled
= base::CommandLine::ForCurrentProcess()->
499 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation
) != "0";
500 SetOverscrollControllerEnabled(overscroll_enabled
);
502 selection_controller_client_
.reset(
503 new TouchSelectionControllerClientAura(this));
504 CreateSelectionController();
507 ////////////////////////////////////////////////////////////////////////////////
508 // RenderWidgetHostViewAura, RenderWidgetHostView implementation:
510 bool RenderWidgetHostViewAura::OnMessageReceived(
511 const IPC::Message
& message
) {
513 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura
, message
)
514 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames
,
515 OnSetNeedsBeginFrames
)
516 IPC_MESSAGE_UNHANDLED(handled
= false)
517 IPC_END_MESSAGE_MAP()
521 void RenderWidgetHostViewAura::InitAsChild(
522 gfx::NativeView parent_view
) {
523 window_
->SetType(ui::wm::WINDOW_TYPE_CONTROL
);
524 window_
->Init(ui::LAYER_SOLID_COLOR
);
525 window_
->SetName("RenderWidgetHostViewAura");
526 window_
->layer()->SetColor(background_color_
);
529 void RenderWidgetHostViewAura::InitAsPopup(
530 RenderWidgetHostView
* parent_host_view
,
531 const gfx::Rect
& bounds_in_screen
) {
532 popup_parent_host_view_
=
533 static_cast<RenderWidgetHostViewAura
*>(parent_host_view
);
535 // TransientWindowClient may be NULL during tests.
536 aura::client::TransientWindowClient
* transient_window_client
=
537 aura::client::GetTransientWindowClient();
538 RenderWidgetHostViewAura
* old_child
=
539 popup_parent_host_view_
->popup_child_host_view_
;
541 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or
542 // similar mechanism to ensure a second popup doesn't cause the first one
543 // to never get a chance to filter events. See crbug.com/160589.
544 DCHECK(old_child
->popup_parent_host_view_
== popup_parent_host_view_
);
545 if (transient_window_client
) {
546 transient_window_client
->RemoveTransientChild(
547 popup_parent_host_view_
->window_
, old_child
->window_
);
549 old_child
->popup_parent_host_view_
= NULL
;
551 popup_parent_host_view_
->popup_child_host_view_
= this;
552 window_
->SetType(ui::wm::WINDOW_TYPE_MENU
);
553 window_
->Init(ui::LAYER_SOLID_COLOR
);
554 window_
->SetName("RenderWidgetHostViewAura");
555 window_
->layer()->SetColor(background_color_
);
557 // Setting the transient child allows for the popup to get mouse events when
558 // in a system modal dialog. Do this before calling ParentWindowWithContext
559 // below so that the transient parent is visible to WindowTreeClient.
560 // This fixes crbug.com/328593.
561 if (transient_window_client
) {
562 transient_window_client
->AddTransientChild(
563 popup_parent_host_view_
->window_
, window_
);
566 aura::Window
* root
= popup_parent_host_view_
->window_
->GetRootWindow();
567 aura::client::ParentWindowWithContext(window_
, root
, bounds_in_screen
);
569 SetBounds(bounds_in_screen
);
571 if (NeedsMouseCapture())
572 window_
->SetCapture();
574 event_filter_for_popup_exit_
.reset(new EventFilterForPopupExit(this));
577 void RenderWidgetHostViewAura::InitAsFullscreen(
578 RenderWidgetHostView
* reference_host_view
) {
579 is_fullscreen_
= true;
580 window_
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
581 window_
->Init(ui::LAYER_SOLID_COLOR
);
582 window_
->SetName("RenderWidgetHostViewAura");
583 window_
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
584 window_
->layer()->SetColor(background_color_
);
586 aura::Window
* parent
= NULL
;
588 if (reference_host_view
) {
589 aura::Window
* reference_window
=
590 static_cast<RenderWidgetHostViewAura
*>(reference_host_view
)->window_
;
591 if (reference_window
) {
592 host_tracker_
.reset(new aura::WindowTracker
);
593 host_tracker_
->Add(reference_window
);
595 gfx::Display display
= gfx::Screen::GetScreenFor(window_
)->
596 GetDisplayNearestWindow(reference_window
);
597 parent
= reference_window
->GetRootWindow();
598 bounds
= display
.bounds();
600 aura::client::ParentWindowWithContext(window_
, parent
, bounds
);
605 RenderWidgetHost
* RenderWidgetHostViewAura::GetRenderWidgetHost() const {
609 void RenderWidgetHostViewAura::Show() {
612 if (!host_
->is_hidden())
615 bool has_saved_frame
= delegated_frame_host_
->HasSavedFrame();
616 ui::LatencyInfo renderer_latency_info
, browser_latency_info
;
617 if (has_saved_frame
) {
618 browser_latency_info
.AddLatencyNumber(
619 ui::TAB_SHOW_COMPONENT
, host_
->GetLatencyComponentId(), 0);
621 renderer_latency_info
.AddLatencyNumber(
622 ui::TAB_SHOW_COMPONENT
, host_
->GetLatencyComponentId(), 0);
624 host_
->WasShown(renderer_latency_info
);
626 aura::Window
* root
= window_
->GetRootWindow();
628 aura::client::CursorClient
* cursor_client
=
629 aura::client::GetCursorClient(root
);
631 NotifyRendererOfCursorVisibilityState(cursor_client
->IsCursorVisible());
634 delegated_frame_host_
->WasShown(browser_latency_info
);
637 if (legacy_render_widget_host_HWND_
) {
638 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent
639 // window before reparenting any plugins. This ensures that the plugin
640 // windows stay on top of the child Zorder in the parent and receive
641 // mouse events, etc.
642 legacy_render_widget_host_HWND_
->UpdateParent(
643 GetNativeView()->GetHost()->GetAcceleratedWidget());
644 legacy_render_widget_host_HWND_
->SetBounds(
645 window_
->GetBoundsInRootWindow());
647 LPARAM lparam
= reinterpret_cast<LPARAM
>(this);
648 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback
, lparam
);
650 if (legacy_render_widget_host_HWND_
)
651 legacy_render_widget_host_HWND_
->Show();
655 void RenderWidgetHostViewAura::Hide() {
658 if (host_
&& !host_
->is_hidden()) {
660 delegated_frame_host_
->WasHidden();
663 constrained_rects_
.clear();
664 aura::WindowTreeHost
* host
= window_
->GetHost();
666 HWND parent
= host
->GetAcceleratedWidget();
667 LPARAM lparam
= reinterpret_cast<LPARAM
>(this);
668 EnumChildWindows(parent
, HideWindowsCallback
, lparam
);
669 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
670 // hidden window on the same lines as Windowed plugin windows.
671 if (legacy_render_widget_host_HWND_
)
672 legacy_render_widget_host_HWND_
->UpdateParent(ui::GetHiddenWindow());
678 if (legacy_render_widget_host_HWND_
)
679 legacy_render_widget_host_HWND_
->Hide();
683 void RenderWidgetHostViewAura::SetSize(const gfx::Size
& size
) {
684 // For a SetSize operation, we don't care what coordinate system the origin
685 // of the window is in, it's only important to make sure that the origin
686 // remains constant after the operation.
687 InternalSetBounds(gfx::Rect(window_
->bounds().origin(), size
));
690 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect
& rect
) {
691 gfx::Point
relative_origin(rect
.origin());
693 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but
694 // Window::SetBounds() takes parent coordinates, so do the conversion here.
695 aura::Window
* root
= window_
->GetRootWindow();
697 aura::client::ScreenPositionClient
* screen_position_client
=
698 aura::client::GetScreenPositionClient(root
);
699 if (screen_position_client
) {
700 screen_position_client
->ConvertPointFromScreen(
701 window_
->parent(), &relative_origin
);
705 InternalSetBounds(gfx::Rect(relative_origin
, rect
.size()));
708 gfx::Vector2dF
RenderWidgetHostViewAura::GetLastScrollOffset() const {
709 return last_scroll_offset_
;
712 gfx::NativeView
RenderWidgetHostViewAura::GetNativeView() const {
716 gfx::NativeViewId
RenderWidgetHostViewAura::GetNativeViewId() const {
718 aura::WindowTreeHost
* host
= window_
->GetHost();
720 return reinterpret_cast<gfx::NativeViewId
>(host
->GetAcceleratedWidget());
722 return static_cast<gfx::NativeViewId
>(NULL
);
725 gfx::NativeViewAccessible
RenderWidgetHostViewAura::GetNativeViewAccessible() {
727 aura::WindowTreeHost
* host
= window_
->GetHost();
729 return static_cast<gfx::NativeViewAccessible
>(NULL
);
730 BrowserAccessibilityManager
* manager
=
731 host_
->GetOrCreateRootBrowserAccessibilityManager();
733 return manager
->GetRoot()->ToBrowserAccessibilityWin();
737 return static_cast<gfx::NativeViewAccessible
>(NULL
);
740 ui::TextInputClient
* RenderWidgetHostViewAura::GetTextInputClient() {
744 void RenderWidgetHostViewAura::OnSetNeedsBeginFrames(bool needs_begin_frames
) {
745 begin_frame_observer_proxy_
.SetNeedsBeginFrames(needs_begin_frames
);
748 void RenderWidgetHostViewAura::SendBeginFrame(const cc::BeginFrameArgs
& args
) {
749 delegated_frame_host_
->SetVSyncParameters(args
.frame_time
, args
.interval
);
750 host_
->Send(new ViewMsg_BeginFrame(host_
->GetRoutingID(), args
));
753 void RenderWidgetHostViewAura::SetKeyboardFocus() {
756 aura::WindowTreeHost
* host
= window_
->GetHost();
758 ::SetFocus(host
->GetAcceleratedWidget());
761 if (host_
&& set_focus_on_mouse_down_
) {
762 set_focus_on_mouse_down_
= false;
767 RenderFrameHostImpl
* RenderWidgetHostViewAura::GetFocusedFrame() {
768 if (!host_
->IsRenderView())
770 RenderViewHost
* rvh
= RenderViewHost::From(host_
);
771 FrameTreeNode
* focused_frame
=
772 rvh
->GetDelegate()->GetFrameTree()->GetFocusedFrame();
776 return focused_frame
->current_frame_host();
779 bool RenderWidgetHostViewAura::CanRendererHandleEvent(
780 const ui::MouseEvent
* event
,
782 bool selection_popup
) {
784 bool showing_context_menu
= showing_context_menu_
;
785 showing_context_menu_
= false;
788 if (event
->type() == ui::ET_MOUSE_CAPTURE_CHANGED
)
791 if ((mouse_locked
|| selection_popup
) &&
792 (event
->type() == ui::ET_MOUSE_EXITED
))
796 // Don't forward the mouse leave message which is received when the context
797 // menu is displayed by the page. This confuses the page and causes state
799 if (showing_context_menu
) {
800 if (event
->type() == ui::ET_MOUSE_EXITED
)
803 // Renderer cannot handle WM_XBUTTON or NC events.
804 switch (event
->native_event().message
) {
807 case WM_XBUTTONDBLCLK
:
808 case WM_NCMOUSELEAVE
:
810 case WM_NCLBUTTONDOWN
:
812 case WM_NCLBUTTONDBLCLK
:
813 case WM_NCRBUTTONDOWN
:
815 case WM_NCRBUTTONDBLCLK
:
816 case WM_NCMBUTTONDOWN
:
818 case WM_NCMBUTTONDBLCLK
:
819 case WM_NCXBUTTONDOWN
:
821 case WM_NCXBUTTONDBLCLK
:
826 #elif defined(USE_X11)
827 // Renderer only supports standard mouse buttons, so ignore programmable
829 switch (event
->type()) {
830 case ui::ET_MOUSE_PRESSED
:
831 case ui::ET_MOUSE_RELEASED
: {
832 const int kAllowedButtons
= ui::EF_LEFT_MOUSE_BUTTON
|
833 ui::EF_MIDDLE_MOUSE_BUTTON
|
834 ui::EF_RIGHT_MOUSE_BUTTON
;
835 return (event
->flags() & kAllowedButtons
) != 0;
844 void RenderWidgetHostViewAura::HandleParentBoundsChanged() {
845 SnapToPhysicalPixelBoundary();
847 if (legacy_render_widget_host_HWND_
) {
848 legacy_render_widget_host_HWND_
->SetBounds(
849 window_
->GetBoundsInRootWindow());
853 host_
->SendScreenRects();
856 void RenderWidgetHostViewAura::ParentHierarchyChanged() {
857 ancestor_window_observer_
.reset(new WindowAncestorObserver(this));
858 // Snap when we receive a hierarchy changed. http://crbug.com/388908.
859 HandleParentBoundsChanged();
862 void RenderWidgetHostViewAura::MovePluginWindows(
863 const std::vector
<WebPluginGeometry
>& plugin_window_moves
) {
865 // We need to clip the rectangle to the tab's viewport, otherwise we will draw
866 // over the browser UI.
867 if (!window_
->GetRootWindow()) {
868 DCHECK(plugin_window_moves
.empty());
871 HWND parent
= window_
->GetHost()->GetAcceleratedWidget();
872 gfx::Rect view_bounds
= window_
->GetBoundsInRootWindow();
873 std::vector
<WebPluginGeometry
> moves
= plugin_window_moves
;
875 gfx::Rect
view_port(view_bounds
.size());
877 for (size_t i
= 0; i
< moves
.size(); ++i
) {
878 gfx::Rect
clip(moves
[i
].clip_rect
);
879 gfx::Vector2d
view_port_offset(
880 moves
[i
].window_rect
.OffsetFromOrigin());
881 clip
.Offset(view_port_offset
);
882 clip
.Intersect(view_port
);
883 clip
.Offset(-view_port_offset
);
884 moves
[i
].clip_rect
= clip
;
886 moves
[i
].window_rect
.Offset(view_bounds
.OffsetFromOrigin());
888 plugin_window_moves_
[moves
[i
].window
] = moves
[i
];
890 // constrained_rects_ are relative to the root window. We want to convert
891 // them to be relative to the plugin window.
892 for (size_t j
= 0; j
< constrained_rects_
.size(); ++j
) {
893 gfx::Rect offset_cutout
= constrained_rects_
[j
];
894 offset_cutout
-= moves
[i
].window_rect
.OffsetFromOrigin();
895 moves
[i
].cutout_rects
.push_back(offset_cutout
);
899 MovePluginWindowsHelper(parent
, moves
);
901 // Make sure each plugin window (or its wrapper if it exists) has a pointer to
903 for (size_t i
= 0; i
< moves
.size(); ++i
) {
904 HWND window
= moves
[i
].window
;
905 if (GetParent(window
) != parent
) {
906 window
= GetParent(window
);
908 if (!GetProp(window
, kWidgetOwnerProperty
))
909 SetProp(window
, kWidgetOwnerProperty
, this);
911 #endif // defined(OS_WIN)
914 void RenderWidgetHostViewAura::Focus() {
915 // Make sure we have a FocusClient before attempting to Focus(). In some
916 // situations we may not yet be in a valid Window hierarchy (such as reloading
917 // after out of memory discarded the tab).
918 aura::client::FocusClient
* client
= aura::client::GetFocusClient(window_
);
923 bool RenderWidgetHostViewAura::HasFocus() const {
924 return window_
->HasFocus();
927 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const {
928 return delegated_frame_host_
->CanCopyToBitmap();
931 bool RenderWidgetHostViewAura::IsShowing() {
932 return window_
->IsVisible();
935 gfx::Rect
RenderWidgetHostViewAura::GetViewBounds() const {
936 return window_
->GetBoundsInScreen();
939 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color
) {
940 RenderWidgetHostViewBase::SetBackgroundColor(color
);
941 bool opaque
= GetBackgroundOpaque();
942 host_
->SetBackgroundOpaque(opaque
);
943 window_
->layer()->SetFillsBoundsOpaquely(opaque
);
944 window_
->layer()->SetColor(color
);
947 gfx::Size
RenderWidgetHostViewAura::GetVisibleViewportSize() const {
948 gfx::Rect
requested_rect(GetRequestedRendererSize());
949 requested_rect
.Inset(insets_
);
950 return requested_rect
.size();
953 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets
& insets
) {
954 if (insets
!= insets_
) {
960 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor
& cursor
) {
961 current_cursor_
= cursor
;
962 const gfx::Display display
= gfx::Screen::GetScreenFor(window_
)->
963 GetDisplayNearestWindow(window_
);
964 current_cursor_
.SetDisplayInfo(display
);
965 UpdateCursorIfOverSelf();
968 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading
) {
969 is_loading_
= is_loading
;
970 UpdateCursorIfOverSelf();
973 void RenderWidgetHostViewAura::TextInputStateChanged(
974 const ViewHostMsg_TextInputState_Params
& params
) {
975 if (text_input_type_
!= params
.type
||
976 text_input_mode_
!= params
.mode
||
977 can_compose_inline_
!= params
.can_compose_inline
||
978 text_input_flags_
!= params
.flags
) {
979 text_input_type_
= params
.type
;
980 text_input_mode_
= params
.mode
;
981 can_compose_inline_
= params
.can_compose_inline
;
982 text_input_flags_
= params
.flags
;
983 if (GetInputMethod())
984 GetInputMethod()->OnTextInputTypeChanged(this);
986 if (params
.show_ime_if_needed
&& params
.type
!= ui::TEXT_INPUT_TYPE_NONE
) {
987 if (GetInputMethod())
988 GetInputMethod()->ShowImeIfNeeded();
992 void RenderWidgetHostViewAura::ImeCancelComposition() {
993 if (GetInputMethod())
994 GetInputMethod()->CancelComposition(this);
995 has_composition_text_
= false;
998 void RenderWidgetHostViewAura::ImeCompositionRangeChanged(
999 const gfx::Range
& range
,
1000 const std::vector
<gfx::Rect
>& character_bounds
) {
1001 composition_character_bounds_
= character_bounds
;
1004 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status
,
1006 UpdateCursorIfOverSelf();
1010 void RenderWidgetHostViewAura::Destroy() {
1011 // Beware, this function is not called on all destruction paths. It will
1012 // implicitly end up calling ~RenderWidgetHostViewAura though, so all
1013 // destruction/cleanup code should happen there, not here.
1014 in_shutdown_
= true;
1018 void RenderWidgetHostViewAura::SetTooltipText(
1019 const base::string16
& tooltip_text
) {
1020 tooltip_
= tooltip_text
;
1021 aura::Window
* root_window
= window_
->GetRootWindow();
1022 aura::client::TooltipClient
* tooltip_client
=
1023 aura::client::GetTooltipClient(root_window
);
1024 if (tooltip_client
) {
1025 tooltip_client
->UpdateTooltip(window_
);
1026 // Content tooltips should be visible indefinitely.
1027 tooltip_client
->SetTooltipShownTimeout(window_
, 0);
1031 void RenderWidgetHostViewAura::SelectionChanged(const base::string16
& text
,
1033 const gfx::Range
& range
) {
1034 RenderWidgetHostViewBase::SelectionChanged(text
, offset
, range
);
1036 #if defined(USE_X11) && !defined(OS_CHROMEOS)
1037 if (text
.empty() || range
.is_empty())
1039 size_t pos
= range
.GetMin() - offset
;
1040 size_t n
= range
.length();
1042 DCHECK(pos
+ n
<= text
.length()) << "The text can not fully cover range.";
1043 if (pos
>= text
.length()) {
1044 NOTREACHED() << "The text can not cover range.";
1048 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
1049 ui::ScopedClipboardWriter
clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION
);
1050 clipboard_writer
.WriteText(text
.substr(pos
, n
));
1051 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
1054 gfx::Size
RenderWidgetHostViewAura::GetRequestedRendererSize() const {
1055 return delegated_frame_host_
->GetRequestedRendererSize();
1058 void RenderWidgetHostViewAura::SelectionBoundsChanged(
1059 const ViewHostMsg_SelectionBounds_Params
& params
) {
1060 ui::SelectionBound anchor_bound
, focus_bound
;
1061 anchor_bound
.SetEdge(params
.anchor_rect
.origin(),
1062 params
.anchor_rect
.bottom_left());
1063 focus_bound
.SetEdge(params
.focus_rect
.origin(),
1064 params
.focus_rect
.bottom_left());
1066 if (params
.anchor_rect
== params
.focus_rect
) {
1067 anchor_bound
.set_type(ui::SelectionBound::CENTER
);
1068 focus_bound
.set_type(ui::SelectionBound::CENTER
);
1070 // Whether text is LTR at the anchor handle.
1071 bool anchor_LTR
= params
.anchor_dir
== blink::WebTextDirectionLeftToRight
;
1072 // Whether text is LTR at the focus handle.
1073 bool focus_LTR
= params
.focus_dir
== blink::WebTextDirectionLeftToRight
;
1075 if ((params
.is_anchor_first
&& anchor_LTR
) ||
1076 (!params
.is_anchor_first
&& !anchor_LTR
)) {
1077 anchor_bound
.set_type(ui::SelectionBound::LEFT
);
1079 anchor_bound
.set_type(ui::SelectionBound::RIGHT
);
1081 if ((params
.is_anchor_first
&& focus_LTR
) ||
1082 (!params
.is_anchor_first
&& !focus_LTR
)) {
1083 focus_bound
.set_type(ui::SelectionBound::RIGHT
);
1085 focus_bound
.set_type(ui::SelectionBound::LEFT
);
1089 if (anchor_bound
== selection_anchor_
&& focus_bound
== selection_focus_
)
1092 selection_anchor_
= anchor_bound
;
1093 selection_focus_
= focus_bound
;
1094 if (GetInputMethod())
1095 GetInputMethod()->OnCaretBoundsChanged(this);
1098 void RenderWidgetHostViewAura::CopyFromCompositingSurface(
1099 const gfx::Rect
& src_subrect
,
1100 const gfx::Size
& dst_size
,
1101 ReadbackRequestCallback
& callback
,
1102 const SkColorType preferred_color_type
) {
1103 delegated_frame_host_
->CopyFromCompositingSurface(
1104 src_subrect
, dst_size
, callback
, preferred_color_type
);
1107 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceToVideoFrame(
1108 const gfx::Rect
& src_subrect
,
1109 const scoped_refptr
<media::VideoFrame
>& target
,
1110 const base::Callback
<void(bool)>& callback
) {
1111 delegated_frame_host_
->CopyFromCompositingSurfaceToVideoFrame(
1112 src_subrect
, target
, callback
);
1115 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const {
1116 return delegated_frame_host_
->CanCopyToVideoFrame();
1119 bool RenderWidgetHostViewAura::CanSubscribeFrame() const {
1120 return delegated_frame_host_
->CanSubscribeFrame();
1123 void RenderWidgetHostViewAura::BeginFrameSubscription(
1124 scoped_ptr
<RenderWidgetHostViewFrameSubscriber
> subscriber
) {
1125 delegated_frame_host_
->BeginFrameSubscription(subscriber
.Pass());
1128 void RenderWidgetHostViewAura::EndFrameSubscription() {
1129 delegated_frame_host_
->EndFrameSubscription();
1133 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
1134 return (legacy_render_widget_host_HWND_
!= NULL
);
1137 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects(
1138 const std::vector
<gfx::Rect
>& rects
) {
1139 // Check this before setting constrained_rects_, so that next time they're set
1140 // and we have a root window we don't early return.
1141 if (!window_
->GetHost())
1144 if (rects
== constrained_rects_
)
1147 constrained_rects_
= rects
;
1149 HWND parent
= window_
->GetHost()->GetAcceleratedWidget();
1150 CutoutRectsParams params
;
1151 params
.widget
= this;
1152 params
.cutout_rects
= constrained_rects_
;
1153 params
.geometry
= &plugin_window_moves_
;
1154 LPARAM lparam
= reinterpret_cast<LPARAM
>(¶ms
);
1155 EnumChildWindows(parent
, SetCutoutRectsCallback
, lparam
);
1158 void RenderWidgetHostViewAura::UpdateMouseLockRegion() {
1159 // Clip the cursor if chrome is running on regular desktop.
1160 if (gfx::Screen::GetScreenFor(window_
) == gfx::Screen::GetNativeScreen()) {
1162 gfx::win::DIPToScreenRect(window_
->GetBoundsInScreen()).ToRECT();
1163 ::ClipCursor(&window_rect
);
1167 void RenderWidgetHostViewAura::OnLegacyWindowDestroyed() {
1168 legacy_render_widget_host_HWND_
= NULL
;
1169 legacy_window_destroyed_
= true;
1173 void RenderWidgetHostViewAura::OnSwapCompositorFrame(
1174 uint32 output_surface_id
,
1175 scoped_ptr
<cc::CompositorFrame
> frame
) {
1176 TRACE_EVENT0("content", "RenderWidgetHostViewAura::OnSwapCompositorFrame");
1178 last_scroll_offset_
= frame
->metadata
.root_scroll_offset
;
1179 if (!frame
->delegated_frame_data
)
1181 delegated_frame_host_
->SwapDelegatedFrame(
1182 output_surface_id
, frame
->delegated_frame_data
.Pass(),
1183 frame
->metadata
.device_scale_factor
, frame
->metadata
.latency_info
,
1184 &frame
->metadata
.satisfies_sequences
);
1185 SelectionUpdated(frame
->metadata
.selection
.is_editable
,
1186 frame
->metadata
.selection
.is_empty_text_form_control
,
1187 ConvertSelectionBound(frame
->metadata
.selection
.start
),
1188 ConvertSelectionBound(frame
->metadata
.selection
.end
));
1191 void RenderWidgetHostViewAura::DidStopFlinging() {
1192 selection_controller_client_
->OnScrollCompleted();
1196 void RenderWidgetHostViewAura::SetParentNativeViewAccessible(
1197 gfx::NativeViewAccessible accessible_parent
) {
1200 gfx::NativeViewId
RenderWidgetHostViewAura::GetParentForWindowlessPlugin()
1202 if (legacy_render_widget_host_HWND_
) {
1203 return reinterpret_cast<gfx::NativeViewId
>(
1204 legacy_render_widget_host_HWND_
->hwnd());
1210 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
1211 const gfx::Size
& desired_size
) {
1212 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
1213 // matter what is returned here as GetBackingStore is the only caller of this
1214 // method. TODO(jbates) implement this if other Aura code needs it.
1218 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo
* results
) {
1219 GetScreenInfoForWindow(results
, window_
->GetRootWindow() ? window_
: NULL
);
1222 bool RenderWidgetHostViewAura::GetScreenColorProfile(
1223 std::vector
<char>* color_profile
) {
1224 DCHECK(color_profile
->empty());
1225 gfx::Rect
bounds(window_
->GetToplevelWindow()->GetBoundsInScreen());
1226 return gfx::GetDisplayColorProfile(bounds
, color_profile
);
1229 gfx::Rect
RenderWidgetHostViewAura::GetBoundsInRootWindow() {
1230 aura::Window
* top_level
= window_
->GetToplevelWindow();
1231 gfx::Rect
bounds(top_level
->GetBoundsInScreen());
1234 // TODO(zturner,iyengar): This will break when we remove support for NPAPI and
1235 // remove the legacy hwnd, so a better fix will need to be decided when that
1237 if (UsesNativeWindowFrame()) {
1238 // aura::Window doesn't take into account non-client area of native windows
1239 // (e.g. HWNDs), so for that case ask Windows directly what the bounds are.
1240 aura::WindowTreeHost
* host
= top_level
->GetHost();
1242 return top_level
->GetBoundsInScreen();
1243 RECT window_rect
= {0};
1244 HWND hwnd
= host
->GetAcceleratedWidget();
1245 ::GetWindowRect(hwnd
, &window_rect
);
1246 bounds
= gfx::Rect(window_rect
);
1248 // Maximized windows are outdented from the work area by the frame thickness
1249 // even though this "frame" is not painted. This confuses code (and people)
1250 // that think of a maximized window as corresponding exactly to the work
1251 // area. Correct for this by subtracting the frame thickness back off.
1252 if (::IsZoomed(hwnd
)) {
1253 bounds
.Inset(GetSystemMetrics(SM_CXSIZEFRAME
),
1254 GetSystemMetrics(SM_CYSIZEFRAME
));
1256 bounds
.Inset(GetSystemMetrics(SM_CXPADDEDBORDER
),
1257 GetSystemMetrics(SM_CXPADDEDBORDER
));
1261 bounds
= gfx::win::ScreenToDIPRect(bounds
);
1267 void RenderWidgetHostViewAura::WheelEventAck(
1268 const blink::WebMouseWheelEvent
& event
,
1269 InputEventAckState ack_result
) {
1270 if (overscroll_controller_
) {
1271 overscroll_controller_
->ReceivedEventACK(
1272 event
, (INPUT_EVENT_ACK_STATE_CONSUMED
== ack_result
));
1276 void RenderWidgetHostViewAura::GestureEventAck(
1277 const blink::WebGestureEvent
& event
,
1278 InputEventAckState ack_result
) {
1279 if (overscroll_controller_
) {
1280 overscroll_controller_
->ReceivedEventACK(
1281 event
, (INPUT_EVENT_ACK_STATE_CONSUMED
== ack_result
));
1285 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
1286 const TouchEventWithLatencyInfo
& touch
,
1287 InputEventAckState ack_result
) {
1288 ScopedVector
<ui::TouchEvent
> events
;
1289 aura::WindowTreeHost
* host
= window_
->GetHost();
1290 // |host| is NULL during tests.
1294 ui::EventResult result
= (ack_result
== INPUT_EVENT_ACK_STATE_CONSUMED
)
1298 blink::WebTouchPoint::State required_state
;
1299 switch (touch
.event
.type
) {
1300 case blink::WebInputEvent::TouchStart
:
1301 required_state
= blink::WebTouchPoint::StatePressed
;
1303 case blink::WebInputEvent::TouchEnd
:
1304 required_state
= blink::WebTouchPoint::StateReleased
;
1306 case blink::WebInputEvent::TouchMove
:
1307 required_state
= blink::WebTouchPoint::StateMoved
;
1309 case blink::WebInputEvent::TouchCancel
:
1310 required_state
= blink::WebTouchPoint::StateCancelled
;
1313 required_state
= blink::WebTouchPoint::StateUndefined
;
1318 // Only send acks for one changed touch point.
1319 bool sent_ack
= false;
1320 for (size_t i
= 0; i
< touch
.event
.touchesLength
; ++i
) {
1321 if (touch
.event
.touches
[i
].state
== required_state
) {
1323 host
->dispatcher()->ProcessedTouchEvent(touch
.event
.uniqueTouchEventId
,
1330 scoped_ptr
<SyntheticGestureTarget
>
1331 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1332 return scoped_ptr
<SyntheticGestureTarget
>(
1333 new SyntheticGestureTargetAura(host_
));
1336 InputEventAckState
RenderWidgetHostViewAura::FilterInputEvent(
1337 const blink::WebInputEvent
& input_event
) {
1338 bool consumed
= false;
1339 if (input_event
.type
== WebInputEvent::GestureFlingStart
) {
1340 const WebGestureEvent
& gesture_event
=
1341 static_cast<const WebGestureEvent
&>(input_event
);
1342 // Zero-velocity touchpad flings are an Aura-specific signal that the
1343 // touchpad scroll has ended, and should not be forwarded to the renderer.
1344 if (gesture_event
.sourceDevice
== blink::WebGestureDeviceTouchpad
&&
1345 !gesture_event
.data
.flingStart
.velocityX
&&
1346 !gesture_event
.data
.flingStart
.velocityY
) {
1351 if (overscroll_controller_
)
1352 consumed
|= overscroll_controller_
->WillHandleEvent(input_event
);
1354 // Touch events should always propagate to the renderer.
1355 if (WebTouchEvent::isTouchEventType(input_event
.type
))
1356 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED
;
1358 // Reporting consumed for a fling suggests that there's now an *active* fling
1359 // that requires both animation and a fling-end notification. However, the
1360 // OverscrollController consumes a fling to stop its propagation; it doesn't
1361 // actually tick a fling animation. Report no consumer to convey this.
1362 if (consumed
&& input_event
.type
== blink::WebInputEvent::GestureFlingStart
)
1363 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
;
1365 return consumed
? INPUT_EVENT_ACK_STATE_CONSUMED
1366 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED
;
1369 BrowserAccessibilityManager
*
1370 RenderWidgetHostViewAura::CreateBrowserAccessibilityManager(
1371 BrowserAccessibilityDelegate
* delegate
) {
1372 BrowserAccessibilityManager
* manager
= NULL
;
1374 manager
= new BrowserAccessibilityManagerWin(
1375 BrowserAccessibilityManagerWin::GetEmptyDocument(), delegate
);
1377 manager
= BrowserAccessibilityManager::Create(
1378 BrowserAccessibilityManager::GetEmptyDocument(), delegate
);
1383 gfx::AcceleratedWidget
1384 RenderWidgetHostViewAura::AccessibilityGetAcceleratedWidget() {
1386 if (legacy_render_widget_host_HWND_
)
1387 return legacy_render_widget_host_HWND_
->hwnd();
1389 return gfx::kNullAcceleratedWidget
;
1392 gfx::NativeViewAccessible
1393 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() {
1395 if (legacy_render_widget_host_HWND_
)
1396 return legacy_render_widget_host_HWND_
->window_accessible();
1401 gfx::GLSurfaceHandle
RenderWidgetHostViewAura::GetCompositingSurface() {
1402 return ImageTransportFactory::GetInstance()->GetSharedSurfaceHandle();
1405 void RenderWidgetHostViewAura::ShowDisambiguationPopup(
1406 const gfx::Rect
& rect_pixels
,
1407 const SkBitmap
& zoomed_bitmap
) {
1408 RenderViewHostDelegate
* delegate
= NULL
;
1409 if (host_
->IsRenderView())
1410 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1411 // Suppress the link disambiguation popup if the virtual keyboard is currently
1412 // requested, as it doesn't interact well with the keyboard.
1413 if (delegate
&& delegate
->IsVirtualKeyboardRequested())
1416 // |target_rect| is provided in pixels, not DIPs. So we convert it to DIPs
1417 // by scaling it by the inverse of the device scale factor.
1418 gfx::RectF
screen_target_rect_f(rect_pixels
);
1419 screen_target_rect_f
.Scale(1.0f
/ current_device_scale_factor_
);
1420 disambiguation_target_rect_
= gfx::ToEnclosingRect(screen_target_rect_f
);
1422 float scale
= static_cast<float>(zoomed_bitmap
.width()) /
1423 static_cast<float>(rect_pixels
.width());
1424 gfx::Size
zoomed_size(gfx::ToCeiledSize(
1425 gfx::ScaleSize(disambiguation_target_rect_
.size(), scale
)));
1427 // Save of a copy of the |last_scroll_offset_| for comparison when the copy
1428 // callback fires, to ensure that we haven't scrolled.
1429 disambiguation_scroll_offset_
= last_scroll_offset_
;
1431 CopyFromCompositingSurface(
1432 disambiguation_target_rect_
,
1434 base::Bind(&RenderWidgetHostViewAura::DisambiguationPopupRendered
,
1435 weak_ptr_factory_
.GetWeakPtr()),
1439 void RenderWidgetHostViewAura::DisambiguationPopupRendered(
1440 const SkBitmap
& result
,
1441 ReadbackResponse response
) {
1442 if ((response
!= READBACK_SUCCESS
) ||
1443 disambiguation_scroll_offset_
!= last_scroll_offset_
)
1446 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will
1447 // actually show the disambiguation popup.
1448 RenderViewHostDelegate
* delegate
= NULL
;
1449 if (host_
->IsRenderView())
1450 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1451 RenderViewHostDelegateView
* delegate_view
= NULL
;
1453 delegate_view
= delegate
->GetDelegateView();
1454 if (delegate
->IsVirtualKeyboardRequested())
1457 if (delegate_view
) {
1458 delegate_view
->ShowDisambiguationPopup(
1459 disambiguation_target_rect_
,
1461 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationGesture
,
1462 weak_ptr_factory_
.GetWeakPtr()),
1463 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationMouse
,
1464 weak_ptr_factory_
.GetWeakPtr()));
1468 void RenderWidgetHostViewAura::HideDisambiguationPopup() {
1469 RenderViewHostDelegate
* delegate
= NULL
;
1470 if (host_
->IsRenderView())
1471 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1472 RenderViewHostDelegateView
* delegate_view
= NULL
;
1474 delegate_view
= delegate
->GetDelegateView();
1476 delegate_view
->HideDisambiguationPopup();
1479 void RenderWidgetHostViewAura::ProcessDisambiguationGesture(
1480 ui::GestureEvent
* event
) {
1481 blink::WebGestureEvent web_gesture
= content::MakeWebGestureEvent(*event
);
1482 // If we fail to make a WebGestureEvent that is a Tap from the provided event,
1483 // don't forward it to Blink.
1484 if (web_gesture
.type
< blink::WebInputEvent::Type::GestureTap
||
1485 web_gesture
.type
> blink::WebInputEvent::Type::GestureTapCancel
)
1488 host_
->ForwardGestureEvent(web_gesture
);
1491 void RenderWidgetHostViewAura::ProcessDisambiguationMouse(
1492 ui::MouseEvent
* event
) {
1493 blink::WebMouseEvent web_mouse
= content::MakeWebMouseEvent(*event
);
1494 host_
->ForwardMouseEvent(web_mouse
);
1497 bool RenderWidgetHostViewAura::LockMouse() {
1498 aura::Window
* root_window
= window_
->GetRootWindow();
1505 mouse_locked_
= true;
1506 #if !defined(OS_WIN)
1507 window_
->SetCapture();
1509 UpdateMouseLockRegion();
1511 aura::client::CursorClient
* cursor_client
=
1512 aura::client::GetCursorClient(root_window
);
1513 if (cursor_client
) {
1514 cursor_client
->HideCursor();
1515 cursor_client
->LockCursor();
1518 if (ShouldMoveToCenter()) {
1519 synthetic_move_sent_
= true;
1520 window_
->MoveCursorTo(gfx::Rect(window_
->bounds().size()).CenterPoint());
1522 tooltip_disabler_
.reset(new aura::client::ScopedTooltipDisabler(root_window
));
1526 void RenderWidgetHostViewAura::UnlockMouse() {
1527 tooltip_disabler_
.reset();
1529 aura::Window
* root_window
= window_
->GetRootWindow();
1530 if (!mouse_locked_
|| !root_window
)
1533 mouse_locked_
= false;
1535 if (window_
->HasCapture())
1536 window_
->ReleaseCapture();
1542 window_
->MoveCursorTo(unlocked_mouse_position_
);
1543 aura::client::CursorClient
* cursor_client
=
1544 aura::client::GetCursorClient(root_window
);
1545 if (cursor_client
) {
1546 cursor_client
->UnlockCursor();
1547 cursor_client
->ShowCursor();
1550 host_
->LostMouseLock();
1553 ////////////////////////////////////////////////////////////////////////////////
1554 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
1555 void RenderWidgetHostViewAura::SetCompositionText(
1556 const ui::CompositionText
& composition
) {
1560 // TODO(suzhe): convert both renderer_host and renderer to use
1561 // ui::CompositionText.
1562 std::vector
<blink::WebCompositionUnderline
> underlines
;
1563 underlines
.reserve(composition
.underlines
.size());
1564 for (std::vector
<ui::CompositionUnderline
>::const_iterator it
=
1565 composition
.underlines
.begin();
1566 it
!= composition
.underlines
.end(); ++it
) {
1567 underlines
.push_back(
1568 blink::WebCompositionUnderline(static_cast<unsigned>(it
->start_offset
),
1569 static_cast<unsigned>(it
->end_offset
),
1572 it
->background_color
));
1575 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
1576 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
1577 host_
->ImeSetComposition(composition
.text
, underlines
,
1578 composition
.selection
.end(),
1579 composition
.selection
.end());
1581 has_composition_text_
= !composition
.text
.empty();
1584 void RenderWidgetHostViewAura::ConfirmCompositionText() {
1585 if (host_
&& has_composition_text_
) {
1586 host_
->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
1589 has_composition_text_
= false;
1592 void RenderWidgetHostViewAura::ClearCompositionText() {
1593 if (host_
&& has_composition_text_
)
1594 host_
->ImeCancelComposition();
1595 has_composition_text_
= false;
1598 void RenderWidgetHostViewAura::InsertText(const base::string16
& text
) {
1599 DCHECK(text_input_type_
!= ui::TEXT_INPUT_TYPE_NONE
);
1601 host_
->ImeConfirmComposition(text
, gfx::Range::InvalidRange(), false);
1602 has_composition_text_
= false;
1605 void RenderWidgetHostViewAura::InsertChar(base::char16 ch
, int flags
) {
1606 if (popup_child_host_view_
&& popup_child_host_view_
->NeedsInputGrab()) {
1607 popup_child_host_view_
->InsertChar(ch
, flags
);
1611 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1612 if (host_
&& (accept_return_character_
|| ch
!= ui::VKEY_RETURN
)) {
1613 double now
= ui::EventTimeForNow().InSecondsF();
1614 // Send a blink::WebInputEvent::Char event to |host_|.
1615 NativeWebKeyboardEvent
webkit_event(ui::ET_KEY_PRESSED
,
1620 ForwardKeyboardEvent(webkit_event
);
1624 ui::TextInputType
RenderWidgetHostViewAura::GetTextInputType() const {
1625 return text_input_type_
;
1628 ui::TextInputMode
RenderWidgetHostViewAura::GetTextInputMode() const {
1629 return text_input_mode_
;
1632 int RenderWidgetHostViewAura::GetTextInputFlags() const {
1633 return text_input_flags_
;
1636 bool RenderWidgetHostViewAura::CanComposeInline() const {
1637 return can_compose_inline_
;
1640 gfx::Rect
RenderWidgetHostViewAura::ConvertRectToScreen(
1641 const gfx::Rect
& rect
) const {
1642 gfx::Point origin
= rect
.origin();
1643 gfx::Point end
= gfx::Point(rect
.right(), rect
.bottom());
1645 aura::Window
* root_window
= window_
->GetRootWindow();
1648 aura::client::ScreenPositionClient
* screen_position_client
=
1649 aura::client::GetScreenPositionClient(root_window
);
1650 if (!screen_position_client
)
1652 screen_position_client
->ConvertPointToScreen(window_
, &origin
);
1653 screen_position_client
->ConvertPointToScreen(window_
, &end
);
1654 return gfx::Rect(origin
.x(),
1656 end
.x() - origin
.x(),
1657 end
.y() - origin
.y());
1660 gfx::Rect
RenderWidgetHostViewAura::ConvertRectFromScreen(
1661 const gfx::Rect
& rect
) const {
1662 gfx::Point origin
= rect
.origin();
1663 gfx::Point end
= gfx::Point(rect
.right(), rect
.bottom());
1665 aura::Window
* root_window
= window_
->GetRootWindow();
1667 aura::client::ScreenPositionClient
* screen_position_client
=
1668 aura::client::GetScreenPositionClient(root_window
);
1669 screen_position_client
->ConvertPointFromScreen(window_
, &origin
);
1670 screen_position_client
->ConvertPointFromScreen(window_
, &end
);
1671 return gfx::Rect(origin
.x(),
1673 end
.x() - origin
.x(),
1674 end
.y() - origin
.y());
1680 gfx::Rect
RenderWidgetHostViewAura::GetCaretBounds() const {
1681 return ConvertRectToScreen(
1682 ui::RectBetweenSelectionBounds(selection_anchor_
, selection_focus_
));
1685 bool RenderWidgetHostViewAura::GetCompositionCharacterBounds(
1687 gfx::Rect
* rect
) const {
1689 if (index
>= composition_character_bounds_
.size())
1691 *rect
= ConvertRectToScreen(composition_character_bounds_
[index
]);
1695 bool RenderWidgetHostViewAura::HasCompositionText() const {
1696 return has_composition_text_
;
1699 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range
* range
) const {
1700 range
->set_start(selection_text_offset_
);
1701 range
->set_end(selection_text_offset_
+ selection_text_
.length());
1705 bool RenderWidgetHostViewAura::GetCompositionTextRange(
1706 gfx::Range
* range
) const {
1707 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1712 bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range
* range
) const {
1713 range
->set_start(selection_range_
.start());
1714 range
->set_end(selection_range_
.end());
1718 bool RenderWidgetHostViewAura::SetSelectionRange(const gfx::Range
& range
) {
1719 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1724 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range
& range
) {
1725 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1730 bool RenderWidgetHostViewAura::GetTextFromRange(
1731 const gfx::Range
& range
,
1732 base::string16
* text
) const {
1733 gfx::Range
selection_text_range(selection_text_offset_
,
1734 selection_text_offset_
+ selection_text_
.length());
1736 if (!selection_text_range
.Contains(range
)) {
1740 if (selection_text_range
.EqualsIgnoringDirection(range
)) {
1741 // Avoid calling substr whose performance is low.
1742 *text
= selection_text_
;
1744 *text
= selection_text_
.substr(
1745 range
.GetMin() - selection_text_offset_
,
1751 void RenderWidgetHostViewAura::OnInputMethodChanged() {
1755 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
1759 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
1760 base::i18n::TextDirection direction
) {
1763 host_
->UpdateTextDirection(
1764 direction
== base::i18n::RIGHT_TO_LEFT
?
1765 blink::WebTextDirectionRightToLeft
:
1766 blink::WebTextDirectionLeftToRight
);
1767 host_
->NotifyTextDirection();
1771 void RenderWidgetHostViewAura::ExtendSelectionAndDelete(
1772 size_t before
, size_t after
) {
1773 RenderFrameHostImpl
* rfh
= GetFocusedFrame();
1775 rfh
->ExtendSelectionAndDelete(before
, after
);
1778 void RenderWidgetHostViewAura::EnsureCaretInRect(const gfx::Rect
& rect
) {
1779 gfx::Rect
intersected_rect(
1780 gfx::IntersectRects(rect
, window_
->GetBoundsInScreen()));
1782 if (intersected_rect
.IsEmpty())
1785 host_
->ScrollFocusedEditableNodeIntoRect(
1786 ConvertRectFromScreen(intersected_rect
));
1789 bool RenderWidgetHostViewAura::IsEditCommandEnabled(int command_id
) {
1793 void RenderWidgetHostViewAura::SetEditCommandForNextKeyEvent(int command_id
) {
1796 ////////////////////////////////////////////////////////////////////////////////
1797 // RenderWidgetHostViewAura, gfx::DisplayObserver implementation:
1799 void RenderWidgetHostViewAura::OnDisplayAdded(
1800 const gfx::Display
& new_display
) {
1803 void RenderWidgetHostViewAura::OnDisplayRemoved(
1804 const gfx::Display
& old_display
) {
1807 void RenderWidgetHostViewAura::OnDisplayMetricsChanged(
1808 const gfx::Display
& display
, uint32_t metrics
) {
1809 // The screen info should be updated regardless of the metric change.
1810 gfx::Screen
* screen
= gfx::Screen::GetScreenFor(window_
);
1811 if (display
.id() == screen
->GetDisplayNearestWindow(window_
).id()) {
1812 UpdateScreenInfo(window_
);
1813 current_cursor_
.SetDisplayInfo(display
);
1814 UpdateCursorIfOverSelf();
1818 ////////////////////////////////////////////////////////////////////////////////
1819 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
1821 gfx::Size
RenderWidgetHostViewAura::GetMinimumSize() const {
1825 gfx::Size
RenderWidgetHostViewAura::GetMaximumSize() const {
1829 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect
& old_bounds
,
1830 const gfx::Rect
& new_bounds
) {
1831 base::AutoReset
<bool> in_bounds_changed(&in_bounds_changed_
, true);
1832 // We care about this whenever RenderWidgetHostViewAura is not owned by a
1833 // WebContentsViewAura since changes to the Window's bounds need to be
1834 // messaged to the renderer. WebContentsViewAura invokes SetSize() or
1835 // SetBounds() itself. No matter how we got here, any redundant calls are
1837 SetSize(new_bounds
.size());
1839 if (GetInputMethod())
1840 GetInputMethod()->OnCaretBoundsChanged(this);
1843 gfx::NativeCursor
RenderWidgetHostViewAura::GetCursor(const gfx::Point
& point
) {
1845 return ui::kCursorNone
;
1846 return current_cursor_
.GetNativeCursor();
1849 int RenderWidgetHostViewAura::GetNonClientComponent(
1850 const gfx::Point
& point
) const {
1854 bool RenderWidgetHostViewAura::ShouldDescendIntoChildForEventHandling(
1855 aura::Window
* child
,
1856 const gfx::Point
& location
) {
1860 bool RenderWidgetHostViewAura::CanFocus() {
1861 return popup_type_
== blink::WebPopupTypeNone
;
1864 void RenderWidgetHostViewAura::OnCaptureLost() {
1865 host_
->LostCapture();
1868 void RenderWidgetHostViewAura::OnPaint(const ui::PaintContext
& context
) {
1872 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
1873 float device_scale_factor
) {
1874 if (!host_
|| !window_
->GetRootWindow())
1877 UpdateScreenInfo(window_
);
1879 const gfx::Display display
= gfx::Screen::GetScreenFor(window_
)->
1880 GetDisplayNearestWindow(window_
);
1881 DCHECK_EQ(device_scale_factor
, display
.device_scale_factor());
1882 current_cursor_
.SetDisplayInfo(display
);
1883 SnapToPhysicalPixelBoundary();
1886 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window
* window
) {
1889 // If the tab was hidden and it's closed, host_->is_hidden would have been
1890 // reset to false in RenderWidgetHostImpl::RendererExited.
1891 if (!window_
->GetRootWindow() || host_
->is_hidden()) {
1892 parent
= ui::GetHiddenWindow();
1894 parent
= window_
->GetHost()->GetAcceleratedWidget();
1896 LPARAM lparam
= reinterpret_cast<LPARAM
>(this);
1897 EnumChildWindows(parent
, WindowDestroyingCallback
, lparam
);
1899 // The LegacyRenderWidgetHostHWND instance is destroyed when its window is
1900 // destroyed. Normally we control when that happens via the Destroy call
1901 // in the dtor. However there may be cases where the window is destroyed
1902 // by Windows, i.e. the parent window is destroyed before the
1903 // RenderWidgetHostViewAura instance goes away etc. To avoid that we
1904 // destroy the LegacyRenderWidgetHostHWND instance here.
1905 if (legacy_render_widget_host_HWND_
) {
1906 legacy_render_widget_host_HWND_
->set_host(NULL
);
1907 legacy_render_widget_host_HWND_
->Destroy();
1908 // The Destroy call above will delete the LegacyRenderWidgetHostHWND
1910 legacy_render_widget_host_HWND_
= NULL
;
1914 // Make sure that the input method no longer references to this object before
1915 // this object is removed from the root window (i.e. this object loses access
1916 // to the input method).
1917 ui::InputMethod
* input_method
= GetInputMethod();
1919 input_method
->DetachTextInputClient(this);
1921 if (overscroll_controller_
)
1922 overscroll_controller_
->Reset();
1925 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window
* window
) {
1926 // Ask the RWH to drop reference to us.
1927 if (!is_guest_view_hack_
)
1928 host_
->ViewDestroyed();
1933 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible
) {
1936 bool RenderWidgetHostViewAura::HasHitTestMask() const {
1940 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path
* mask
) const {
1943 ////////////////////////////////////////////////////////////////////////////////
1944 // RenderWidgetHostViewAura, ui::EventHandler implementation:
1946 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent
* event
) {
1947 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent");
1949 if (popup_child_host_view_
&& popup_child_host_view_
->NeedsInputGrab()) {
1950 popup_child_host_view_
->OnKeyEvent(event
);
1951 if (event
->handled())
1955 // We need to handle the Escape key for Pepper Flash.
1956 if (is_fullscreen_
&& event
->key_code() == ui::VKEY_ESCAPE
) {
1957 // Focus the window we were created from.
1958 if (host_tracker_
.get() && !host_tracker_
->windows().empty()) {
1959 aura::Window
* host
= *(host_tracker_
->windows().begin());
1960 aura::client::FocusClient
* client
= aura::client::GetFocusClient(host
);
1962 // Calling host->Focus() may delete |this|. We create a local observer
1963 // for that. In that case we exit without further access to any members.
1964 aura::WindowTracker tracker
;
1965 aura::Window
* window
= window_
;
1966 tracker
.Add(window
);
1968 if (!tracker
.Contains(window
)) {
1969 event
->SetHandled();
1976 if (event
->key_code() == ui::VKEY_RETURN
) {
1977 // Do not forward return key release events if no press event was handled.
1978 if (event
->type() == ui::ET_KEY_RELEASED
&& !accept_return_character_
)
1980 // Accept return key character events between press and release events.
1981 accept_return_character_
= event
->type() == ui::ET_KEY_PRESSED
;
1984 // We don't have to communicate with an input method here.
1985 NativeWebKeyboardEvent
webkit_event(*event
);
1986 ForwardKeyboardEvent(webkit_event
);
1988 event
->SetHandled();
1991 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent
* event
) {
1992 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent");
1994 if (mouse_locked_
) {
1995 aura::client::CursorClient
* cursor_client
=
1996 aura::client::GetCursorClient(window_
->GetRootWindow());
1997 DCHECK(!cursor_client
|| !cursor_client
->IsCursorVisible());
1999 if (event
->type() == ui::ET_MOUSEWHEEL
) {
2000 blink::WebMouseWheelEvent mouse_wheel_event
=
2001 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent
&>(*event
));
2002 if (mouse_wheel_event
.deltaX
!= 0 || mouse_wheel_event
.deltaY
!= 0)
2003 host_
->ForwardWheelEvent(mouse_wheel_event
);
2007 gfx::Point
center(gfx::Rect(window_
->bounds().size()).CenterPoint());
2009 // If we receive non client mouse messages while we are in the locked state
2010 // it probably means that the mouse left the borders of our window and
2011 // needs to be moved back to the center.
2012 if (event
->flags() & ui::EF_IS_NON_CLIENT
) {
2013 synthetic_move_sent_
= true;
2014 window_
->MoveCursorTo(center
);
2018 blink::WebMouseEvent mouse_event
= MakeWebMouseEvent(*event
);
2020 bool is_move_to_center_event
= (event
->type() == ui::ET_MOUSE_MOVED
||
2021 event
->type() == ui::ET_MOUSE_DRAGGED
) &&
2022 mouse_event
.x
== center
.x() && mouse_event
.y
== center
.y();
2024 // For fractional scale factors, the conversion from pixels to dip and
2025 // vice versa could result in off by 1 or 2 errors which hurts us because
2026 // we want to avoid sending the artificial move to center event to the
2027 // renderer. Sending the move to center to the renderer cause the cursor
2028 // to bounce around the center of the screen leading to the lock operation
2029 // not working correctly.
2030 // Workaround is to treat a mouse move or drag event off by at most 2 px
2031 // from the center as a move to center event.
2032 if (synthetic_move_sent_
&&
2033 IsFractionalScaleFactor(current_device_scale_factor_
)) {
2034 if (event
->type() == ui::ET_MOUSE_MOVED
||
2035 event
->type() == ui::ET_MOUSE_DRAGGED
) {
2036 if ((abs(mouse_event
.x
- center
.x()) <= 2) &&
2037 (abs(mouse_event
.y
- center
.y()) <= 2)) {
2038 is_move_to_center_event
= true;
2043 ModifyEventMovementAndCoords(&mouse_event
);
2045 bool should_not_forward
= is_move_to_center_event
&& synthetic_move_sent_
;
2046 if (should_not_forward
) {
2047 synthetic_move_sent_
= false;
2049 // Check if the mouse has reached the border and needs to be centered.
2050 if (ShouldMoveToCenter()) {
2051 synthetic_move_sent_
= true;
2052 window_
->MoveCursorTo(center
);
2054 bool is_selection_popup
= popup_child_host_view_
&&
2055 popup_child_host_view_
->NeedsInputGrab();
2056 // Forward event to renderer.
2057 if (CanRendererHandleEvent(event
, mouse_locked_
, is_selection_popup
) &&
2058 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2059 host_
->ForwardMouseEvent(mouse_event
);
2060 // Ensure that we get keyboard focus on mouse down as a plugin window
2061 // may have grabbed keyboard focus.
2062 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2069 // As the overscroll is handled during scroll events from the trackpad, the
2070 // RWHVA window is transformed by the overscroll controller. This transform
2071 // triggers a synthetic mouse-move event to be generated (by the aura
2072 // RootWindow). But this event interferes with the overscroll gesture. So,
2073 // ignore such synthetic mouse-move events if an overscroll gesture is in
2075 if (overscroll_controller_
&&
2076 overscroll_controller_
->overscroll_mode() != OVERSCROLL_NONE
&&
2077 event
->flags() & ui::EF_IS_SYNTHESIZED
&&
2078 (event
->type() == ui::ET_MOUSE_ENTERED
||
2079 event
->type() == ui::ET_MOUSE_EXITED
||
2080 event
->type() == ui::ET_MOUSE_MOVED
)) {
2081 event
->StopPropagation();
2085 if (event
->type() == ui::ET_MOUSEWHEEL
) {
2087 // We get mouse wheel/scroll messages even if we are not in the foreground.
2088 // So here we check if we have any owned popup windows in the foreground and
2090 aura::WindowTreeHost
* host
= window_
->GetHost();
2092 HWND parent
= host
->GetAcceleratedWidget();
2093 HWND toplevel_hwnd
= ::GetAncestor(parent
, GA_ROOT
);
2094 EnumThreadWindows(GetCurrentThreadId(),
2096 reinterpret_cast<LPARAM
>(toplevel_hwnd
));
2099 // The Disambiguation popup does not parent itself from this window, so we
2100 // manually dismiss it.
2101 HideDisambiguationPopup();
2103 blink::WebMouseWheelEvent mouse_wheel_event
=
2104 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent
&>(*event
));
2105 if (mouse_wheel_event
.deltaX
!= 0 || mouse_wheel_event
.deltaY
!= 0) {
2106 if (host_
->delegate() && host_
->delegate()->GetInputEventRouter()) {
2107 host_
->delegate()->GetInputEventRouter()->RouteMouseWheelEvent(
2108 this, &mouse_wheel_event
);
2110 ProcessMouseWheelEvent(mouse_wheel_event
);
2114 bool is_selection_popup
=
2115 popup_child_host_view_
&& popup_child_host_view_
->NeedsInputGrab();
2116 if (CanRendererHandleEvent(event
, mouse_locked_
, is_selection_popup
) &&
2117 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2118 // Confirm existing composition text on mouse press, to make sure
2119 // the input caret won't be moved with an ongoing composition text.
2120 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2121 FinishImeCompositionSession();
2123 blink::WebMouseEvent mouse_event
= MakeWebMouseEvent(*event
);
2124 ModifyEventMovementAndCoords(&mouse_event
);
2125 if (host_
->delegate() && host_
->delegate()->GetInputEventRouter()) {
2126 host_
->delegate()->GetInputEventRouter()->RouteMouseEvent(this,
2129 ProcessMouseEvent(mouse_event
);
2132 // Ensure that we get keyboard focus on mouse down as a plugin window may
2133 // have grabbed keyboard focus.
2134 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2139 switch (event
->type()) {
2140 case ui::ET_MOUSE_PRESSED
:
2141 window_
->SetCapture();
2143 case ui::ET_MOUSE_RELEASED
:
2144 if (!NeedsMouseCapture())
2145 window_
->ReleaseCapture();
2151 // Needed to propagate mouse event to |window_->parent()->delegate()|, but
2152 // note that it might be something other than a WebContentsViewAura instance.
2153 // TODO(pkotwicz): Find a better way of doing this.
2154 // In fullscreen mode which is typically used by flash, don't forward
2155 // the mouse events to the parent. The renderer and the plugin process
2156 // handle these events.
2157 if (!is_fullscreen_
&& window_
->parent() && window_
->parent()->delegate() &&
2158 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2159 event
->ConvertLocationToTarget(window_
, window_
->parent());
2160 window_
->parent()->delegate()->OnMouseEvent(event
);
2163 if (!IsXButtonUpEvent(event
))
2164 event
->SetHandled();
2167 uint32_t RenderWidgetHostViewAura::SurfaceIdNamespaceAtPoint(
2168 const gfx::Point
& point
,
2169 gfx::Point
* transformed_point
) {
2171 delegated_frame_host_
->SurfaceIdAtPoint(point
, transformed_point
);
2172 // It is possible that the renderer has not yet produced a surface, in which
2173 // case we return our current namespace.
2175 return GetSurfaceIdNamespace();
2176 return cc::SurfaceIdAllocator::NamespaceForId(id
);
2179 void RenderWidgetHostViewAura::ProcessMouseEvent(
2180 const blink::WebMouseEvent
& event
) {
2181 host_
->ForwardMouseEvent(event
);
2184 void RenderWidgetHostViewAura::ProcessMouseWheelEvent(
2185 const blink::WebMouseWheelEvent
& event
) {
2186 host_
->ForwardWheelEvent(event
);
2189 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent
* event
) {
2190 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent");
2192 if (event
->type() == ui::ET_SCROLL
) {
2193 #if !defined(OS_WIN)
2195 // Investigate if this is true for Windows 8 Metro ASH as well.
2196 if (event
->finger_count() != 2)
2199 blink::WebGestureEvent gesture_event
=
2200 MakeWebGestureEventFlingCancel();
2201 host_
->ForwardGestureEvent(gesture_event
);
2202 blink::WebMouseWheelEvent mouse_wheel_event
=
2203 MakeWebMouseWheelEvent(*event
);
2204 host_
->ForwardWheelEvent(mouse_wheel_event
);
2205 RecordAction(base::UserMetricsAction("TrackpadScroll"));
2206 } else if (event
->type() == ui::ET_SCROLL_FLING_START
||
2207 event
->type() == ui::ET_SCROLL_FLING_CANCEL
) {
2208 blink::WebGestureEvent gesture_event
= MakeWebGestureEvent(*event
);
2209 host_
->ForwardGestureEvent(gesture_event
);
2210 if (event
->type() == ui::ET_SCROLL_FLING_START
)
2211 RecordAction(base::UserMetricsAction("TrackpadScrollFling"));
2214 event
->SetHandled();
2217 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent
* event
) {
2218 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent");
2220 bool had_no_pointer
= !pointer_state_
.GetPointerCount();
2222 // Update the touch event first.
2223 if (!pointer_state_
.OnTouch(*event
)) {
2224 event
->StopPropagation();
2228 blink::WebTouchEvent touch_event
;
2229 bool handled
= selection_controller_
->WillHandleTouchEvent(pointer_state_
);
2231 event
->SetHandled();
2233 touch_event
= ui::CreateWebTouchEventFromMotionEvent(
2234 pointer_state_
, event
->may_cause_scrolling());
2236 pointer_state_
.CleanupRemovedTouchPoints(*event
);
2242 selection_controller_client_
->OnTouchDown();
2243 if (!pointer_state_
.GetPointerCount())
2244 selection_controller_client_
->OnTouchUp();
2246 // It is important to always mark events as being handled asynchronously when
2247 // they are forwarded. This ensures that the current event does not get
2248 // processed by the gesture recognizer before events currently awaiting
2249 // dispatch in the touch queue.
2250 event
->DisableSynchronousHandling();
2252 // Set unchanged touch point to StateStationary for touchmove and
2253 // touchcancel to make sure only send one ack per WebTouchEvent.
2254 MarkUnchangedTouchPointsAsStationary(&touch_event
, event
->touch_id());
2255 host_
->ForwardTouchEventWithLatencyInfo(touch_event
, *event
->latency());
2258 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent
* event
) {
2259 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent");
2261 if ((event
->type() == ui::ET_GESTURE_PINCH_BEGIN
||
2262 event
->type() == ui::ET_GESTURE_PINCH_UPDATE
||
2263 event
->type() == ui::ET_GESTURE_PINCH_END
) && !pinch_zoom_enabled_
) {
2264 event
->SetHandled();
2268 HandleGestureForTouchSelection(event
);
2269 if (event
->handled())
2272 // Confirm existing composition text on TAP gesture, to make sure the input
2273 // caret won't be moved with an ongoing composition text.
2274 if (event
->type() == ui::ET_GESTURE_TAP
)
2275 FinishImeCompositionSession();
2277 blink::WebGestureEvent gesture
= MakeWebGestureEvent(*event
);
2278 if (event
->type() == ui::ET_GESTURE_TAP_DOWN
) {
2279 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an
2280 // event to stop any in-progress flings.
2281 blink::WebGestureEvent fling_cancel
= gesture
;
2282 fling_cancel
.type
= blink::WebInputEvent::GestureFlingCancel
;
2283 fling_cancel
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
2284 host_
->ForwardGestureEvent(fling_cancel
);
2287 if (gesture
.type
!= blink::WebInputEvent::Undefined
) {
2288 host_
->ForwardGestureEventWithLatencyInfo(gesture
, *event
->latency());
2290 if (event
->type() == ui::ET_GESTURE_SCROLL_BEGIN
||
2291 event
->type() == ui::ET_GESTURE_SCROLL_UPDATE
||
2292 event
->type() == ui::ET_GESTURE_SCROLL_END
) {
2293 RecordAction(base::UserMetricsAction("TouchscreenScroll"));
2294 } else if (event
->type() == ui::ET_SCROLL_FLING_START
) {
2295 RecordAction(base::UserMetricsAction("TouchscreenScrollFling"));
2299 // If a gesture is not processed by the webpage, then WebKit processes it
2300 // (e.g. generates synthetic mouse events).
2301 event
->SetHandled();
2304 ////////////////////////////////////////////////////////////////////////////////
2305 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation:
2307 bool RenderWidgetHostViewAura::ShouldActivate() const {
2308 aura::WindowTreeHost
* host
= window_
->GetHost();
2311 const ui::Event
* event
= host
->dispatcher()->current_event();
2314 return is_fullscreen_
;
2317 ////////////////////////////////////////////////////////////////////////////////
2318 // RenderWidgetHostViewAura, aura::client::CursorClientObserver implementation:
2320 void RenderWidgetHostViewAura::OnCursorVisibilityChanged(bool is_visible
) {
2321 NotifyRendererOfCursorVisibilityState(is_visible
);
2324 ////////////////////////////////////////////////////////////////////////////////
2325 // RenderWidgetHostViewAura, aura::client::FocusChangeObserver implementation:
2327 void RenderWidgetHostViewAura::OnWindowFocused(aura::Window
* gained_focus
,
2328 aura::Window
* lost_focus
) {
2329 DCHECK(window_
== gained_focus
|| window_
== lost_focus
);
2330 if (window_
== gained_focus
) {
2331 // We need to honor input bypass if the associated tab is does not want
2332 // input. This gives the current focused window a chance to be the text
2333 // input client and handle events.
2334 if (host_
->ignore_input_events())
2338 host_
->SetActive(true);
2340 ui::InputMethod
* input_method
= GetInputMethod();
2342 // Ask the system-wide IME to send all TextInputClient messages to |this|
2344 input_method
->SetFocusedTextInputClient(this);
2346 // Often the application can set focus to the view in response to a key
2347 // down. However the following char event shouldn't be sent to the web
2349 host_
->SuppressNextCharEvents();
2352 BrowserAccessibilityManager
* manager
=
2353 host_
->GetRootBrowserAccessibilityManager();
2355 manager
->OnWindowFocused();
2356 } else if (window_
== lost_focus
) {
2357 host_
->SetActive(false);
2360 DetachFromInputMethod();
2362 selection_controller_
->HideAndDisallowShowingAutomatically();
2364 if (overscroll_controller_
)
2365 overscroll_controller_
->Cancel();
2367 BrowserAccessibilityManager
* manager
=
2368 host_
->GetRootBrowserAccessibilityManager();
2370 manager
->OnWindowBlurred();
2372 // If we lose the focus while fullscreen, close the window; Pepper Flash
2373 // won't do it for us (unlike NPAPI Flash). However, we do not close the
2374 // window if we lose the focus to a window on another display.
2375 gfx::Screen
* screen
= gfx::Screen::GetScreenFor(window_
);
2376 bool focusing_other_display
=
2377 gained_focus
&& screen
->GetNumDisplays() > 1 &&
2378 (screen
->GetDisplayNearestWindow(window_
).id() !=
2379 screen
->GetDisplayNearestWindow(gained_focus
).id());
2380 if (is_fullscreen_
&& !in_shutdown_
&& !focusing_other_display
) {
2382 // On Windows, if we are switching to a non Aura Window on a different
2383 // screen we should not close the fullscreen window.
2384 if (!gained_focus
) {
2386 ::GetCursorPos(&point
);
2387 if (screen
->GetDisplayNearestWindow(window_
).id() !=
2388 screen
->GetDisplayNearestPoint(gfx::Point(point
)).id())
2396 // Close the child popup window if we lose focus (e.g. due to a JS alert or
2397 // system modal dialog). This is particularly important if
2398 // |popup_child_host_view_| has mouse capture.
2399 if (popup_child_host_view_
)
2400 popup_child_host_view_
->Shutdown();
2404 ////////////////////////////////////////////////////////////////////////////////
2405 // RenderWidgetHostViewAura, aura::WindowTreeHostObserver implementation:
2407 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost
* host
,
2408 const gfx::Point
& new_origin
) {
2409 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved",
2410 "new_origin", new_origin
.ToString());
2412 UpdateScreenInfo(window_
);
2415 ////////////////////////////////////////////////////////////////////////////////
2416 // RenderWidgetHostViewAura, private:
2418 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
2419 selection_controller_
.reset();
2420 selection_controller_client_
.reset();
2422 if (UseSurfacesEnabled() && host_
->delegate() &&
2423 host_
->delegate()->GetInputEventRouter()) {
2424 host_
->delegate()->GetInputEventRouter()->RemoveSurfaceIdNamespaceOwner(
2425 GetSurfaceIdNamespace());
2427 delegated_frame_host_
.reset();
2428 window_observer_
.reset();
2429 if (window_
->GetHost())
2430 window_
->GetHost()->RemoveObserver(this);
2432 if (popup_parent_host_view_
) {
2433 DCHECK(popup_parent_host_view_
->popup_child_host_view_
== NULL
||
2434 popup_parent_host_view_
->popup_child_host_view_
== this);
2435 popup_parent_host_view_
->popup_child_host_view_
= NULL
;
2437 if (popup_child_host_view_
) {
2438 DCHECK(popup_child_host_view_
->popup_parent_host_view_
== NULL
||
2439 popup_child_host_view_
->popup_parent_host_view_
== this);
2440 popup_child_host_view_
->popup_parent_host_view_
= NULL
;
2442 event_filter_for_popup_exit_
.reset();
2443 aura::client::SetTooltipText(window_
, NULL
);
2444 gfx::Screen::GetScreenFor(window_
)->RemoveObserver(this);
2446 // This call is usually no-op since |this| object is already removed from the
2447 // Aura root window and we don't have a way to get an input method object
2448 // associated with the window, but just in case.
2449 DetachFromInputMethod();
2452 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2453 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2455 DCHECK(!legacy_render_widget_host_HWND_
);
2459 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
2460 if (host_
->GetProcess()->FastShutdownStarted())
2463 aura::Window
* root_window
= window_
->GetRootWindow();
2467 gfx::Point root_window_point
=
2468 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint();
2469 aura::client::ScreenPositionClient
* screen_position_client
=
2470 aura::client::GetScreenPositionClient(root_window
);
2471 if (screen_position_client
) {
2472 screen_position_client
->ConvertPointFromScreen(
2473 root_window
, &root_window_point
);
2476 if (root_window
->GetEventHandlerForPoint(root_window_point
) != window_
)
2479 gfx::NativeCursor cursor
= current_cursor_
.GetNativeCursor();
2480 // Do not show loading cursor when the cursor is currently hidden.
2481 if (is_loading_
&& cursor
!= ui::kCursorNone
)
2482 cursor
= ui::kCursorPointer
;
2484 aura::client::CursorClient
* cursor_client
=
2485 aura::client::GetCursorClient(root_window
);
2486 if (cursor_client
) {
2487 cursor_client
->SetCursor(cursor
);
2491 ui::InputMethod
* RenderWidgetHostViewAura::GetInputMethod() const {
2492 aura::Window
* root_window
= window_
->GetRootWindow();
2495 return root_window
->GetHost()->GetInputMethod();
2498 void RenderWidgetHostViewAura::Shutdown() {
2499 if (!in_shutdown_
) {
2500 in_shutdown_
= true;
2505 bool RenderWidgetHostViewAura::NeedsInputGrab() {
2506 return popup_type_
== blink::WebPopupTypePage
;
2509 bool RenderWidgetHostViewAura::NeedsMouseCapture() {
2510 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2511 return NeedsInputGrab();
2516 void RenderWidgetHostViewAura::FinishImeCompositionSession() {
2517 if (!has_composition_text_
)
2520 host_
->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
2523 ImeCancelComposition();
2526 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords(
2527 blink::WebMouseEvent
* event
) {
2528 // If the mouse has just entered, we must report zero movementX/Y. Hence we
2529 // reset any global_mouse_position set previously.
2530 if (event
->type
== blink::WebInputEvent::MouseEnter
||
2531 event
->type
== blink::WebInputEvent::MouseLeave
)
2532 global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2534 // Movement is computed by taking the difference of the new cursor position
2535 // and the previous. Under mouse lock the cursor will be warped back to the
2536 // center so that we are not limited by clipping boundaries.
2537 // We do not measure movement as the delta from cursor to center because
2538 // we may receive more mouse movement events before our warp has taken
2540 event
->movementX
= event
->globalX
- global_mouse_position_
.x();
2541 event
->movementY
= event
->globalY
- global_mouse_position_
.y();
2543 global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2545 // Under mouse lock, coordinates of mouse are locked to what they were when
2546 // mouse lock was entered.
2547 if (mouse_locked_
) {
2548 event
->x
= unlocked_mouse_position_
.x();
2549 event
->y
= unlocked_mouse_position_
.y();
2550 event
->windowX
= unlocked_mouse_position_
.x();
2551 event
->windowY
= unlocked_mouse_position_
.y();
2552 event
->globalX
= unlocked_global_mouse_position_
.x();
2553 event
->globalY
= unlocked_global_mouse_position_
.y();
2555 unlocked_mouse_position_
.SetPoint(event
->x
, event
->y
);
2556 unlocked_global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2560 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState(
2562 if (host_
->is_hidden() ||
2563 (cursor_visibility_state_in_renderer_
== VISIBLE
&& is_visible
) ||
2564 (cursor_visibility_state_in_renderer_
== NOT_VISIBLE
&& !is_visible
))
2567 cursor_visibility_state_in_renderer_
= is_visible
? VISIBLE
: NOT_VISIBLE
;
2568 host_
->SendCursorVisibilityState(is_visible
);
2571 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled
) {
2573 overscroll_controller_
.reset();
2574 else if (!overscroll_controller_
)
2575 overscroll_controller_
.reset(new OverscrollController());
2578 void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() {
2579 // The top left corner of our view in window coordinates might not land on a
2580 // device pixel boundary if we have a non-integer device scale. In that case,
2581 // to avoid the web contents area looking blurry we translate the web contents
2582 // in the +x, +y direction to land on the nearest pixel boundary. This may
2583 // cause the bottom and right edges to be clipped slightly, but that's ok.
2584 aura::Window
* snapped
= NULL
;
2585 // On desktop, use the root window. On alternative environment (ash),
2586 // use the toplevel window which must be already snapped.
2587 if (gfx::Screen::GetScreenFor(window_
) !=
2588 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
)) {
2589 snapped
= window_
->GetRootWindow();
2591 snapped
= window_
->GetToplevelWindow();
2593 if (snapped
&& snapped
!= window_
)
2594 ui::SnapLayerToPhysicalPixelBoundary(snapped
->layer(), window_
->layer());
2596 has_snapped_to_boundary_
= true;
2599 void RenderWidgetHostViewAura::OnShowContextMenu() {
2601 showing_context_menu_
= true;
2605 void RenderWidgetHostViewAura::SetSelectionControllerClientForTest(
2606 scoped_ptr
<TouchSelectionControllerClientAura
> client
) {
2607 selection_controller_client_
.swap(client
);
2608 CreateSelectionController();
2611 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect
& rect
) {
2612 SnapToPhysicalPixelBoundary();
2613 // Don't recursively call SetBounds if this bounds update is the result of
2614 // a Window::SetBoundsInternal call.
2615 if (!in_bounds_changed_
)
2616 window_
->SetBounds(rect
);
2617 host_
->WasResized();
2618 delegated_frame_host_
->WasResized();
2620 // Create the legacy dummy window which corresponds to the bounds of the
2621 // webcontents. This will be passed as the container window for windowless
2623 // Plugins like Flash assume the container window which is returned via the
2624 // NPNVnetscapeWindow property corresponds to the bounds of the webpage.
2625 // This is not true in Aura where we have only HWND which is the main Aura
2626 // window. If we return this window to plugins like Flash then it causes the
2627 // coordinate translations done by these plugins to break.
2628 // Additonally the legacy dummy window is needed for accessibility and for
2629 // scrolling to work in legacy drivers for trackpoints/trackpads, etc.
2630 if (!legacy_window_destroyed_
&& GetNativeViewId()) {
2631 if (!legacy_render_widget_host_HWND_
) {
2632 legacy_render_widget_host_HWND_
= LegacyRenderWidgetHostHWND::Create(
2633 reinterpret_cast<HWND
>(GetNativeViewId()));
2635 if (legacy_render_widget_host_HWND_
) {
2636 legacy_render_widget_host_HWND_
->set_host(this);
2637 legacy_render_widget_host_HWND_
->SetBounds(
2638 window_
->GetBoundsInRootWindow());
2639 // There are cases where the parent window is created, made visible and
2640 // the associated RenderWidget is also visible before the
2641 // LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown
2643 if (!host_
->is_hidden())
2644 legacy_render_widget_host_HWND_
->Show();
2649 UpdateMouseLockRegion();
2653 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip(
2654 const gfx::Rect
& rect
,
2655 const gfx::Rect
& clip
) {
2656 if (!clip
.IsEmpty()) {
2657 gfx::Rect to_paint
= gfx::SubtractRects(rect
, clip
);
2658 if (!to_paint
.IsEmpty())
2659 window_
->SchedulePaintInRect(to_paint
);
2661 window_
->SchedulePaintInRect(rect
);
2665 bool RenderWidgetHostViewAura::ShouldMoveToCenter() {
2666 gfx::Rect rect
= window_
->bounds();
2667 rect
= ConvertRectToScreen(rect
);
2668 int border_x
= rect
.width() * kMouseLockBorderPercentage
/ 100;
2669 int border_y
= rect
.height() * kMouseLockBorderPercentage
/ 100;
2671 return global_mouse_position_
.x() < rect
.x() + border_x
||
2672 global_mouse_position_
.x() > rect
.right() - border_x
||
2673 global_mouse_position_
.y() < rect
.y() + border_y
||
2674 global_mouse_position_
.y() > rect
.bottom() - border_y
;
2677 void RenderWidgetHostViewAura::AddedToRootWindow() {
2678 window_
->GetHost()->AddObserver(this);
2679 UpdateScreenInfo(window_
);
2681 aura::client::CursorClient
* cursor_client
=
2682 aura::client::GetCursorClient(window_
->GetRootWindow());
2683 if (cursor_client
) {
2684 cursor_client
->AddObserver(this);
2685 NotifyRendererOfCursorVisibilityState(cursor_client
->IsCursorVisible());
2688 ui::InputMethod
* input_method
= GetInputMethod();
2690 input_method
->SetFocusedTextInputClient(this);
2694 // The parent may have changed here. Ensure that the legacy window is
2695 // reparented accordingly.
2696 if (legacy_render_widget_host_HWND_
)
2697 legacy_render_widget_host_HWND_
->UpdateParent(
2698 reinterpret_cast<HWND
>(GetNativeViewId()));
2701 delegated_frame_host_
->SetCompositor(window_
->GetHost()->compositor());
2702 if (window_
->GetHost()->compositor())
2703 begin_frame_observer_proxy_
.SetCompositor(window_
->GetHost()->compositor());
2706 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2707 aura::client::CursorClient
* cursor_client
=
2708 aura::client::GetCursorClient(window_
->GetRootWindow());
2710 cursor_client
->RemoveObserver(this);
2712 DetachFromInputMethod();
2714 window_
->GetHost()->RemoveObserver(this);
2715 delegated_frame_host_
->ResetCompositor();
2716 begin_frame_observer_proxy_
.ResetCompositor();
2719 // Update the legacy window's parent temporarily to the desktop window. It
2720 // will eventually get reparented to the right root.
2721 if (legacy_render_widget_host_HWND_
)
2722 legacy_render_widget_host_HWND_
->UpdateParent(::GetDesktopWindow());
2726 void RenderWidgetHostViewAura::DetachFromInputMethod() {
2727 ui::InputMethod
* input_method
= GetInputMethod();
2729 input_method
->DetachTextInputClient(this);
2732 void RenderWidgetHostViewAura::ForwardKeyboardEvent(
2733 const NativeWebKeyboardEvent
& event
) {
2734 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2735 ui::TextEditKeyBindingsDelegateAuraLinux
* keybinding_delegate
=
2736 ui::GetTextEditKeyBindingsDelegate();
2737 std::vector
<ui::TextEditCommandAuraLinux
> commands
;
2738 if (!event
.skip_in_browser
&&
2739 keybinding_delegate
&&
2741 keybinding_delegate
->MatchEvent(*event
.os_event
, &commands
)) {
2742 // Transform from ui/ types to content/ types.
2743 EditCommands edit_commands
;
2744 for (std::vector
<ui::TextEditCommandAuraLinux
>::const_iterator it
=
2745 commands
.begin(); it
!= commands
.end(); ++it
) {
2746 edit_commands
.push_back(EditCommand(it
->GetCommandString(),
2749 host_
->Send(new InputMsg_SetEditCommandsForNextKeyEvent(
2750 host_
->GetRoutingID(), edit_commands
));
2751 NativeWebKeyboardEvent
copy_event(event
);
2752 copy_event
.match_edit_command
= true;
2753 host_
->ForwardKeyboardEvent(copy_event
);
2758 host_
->ForwardKeyboardEvent(event
);
2761 void RenderWidgetHostViewAura::SelectionUpdated(bool is_editable
,
2762 bool is_empty_text_form_control
,
2763 const ui::SelectionBound
& start
,
2764 const ui::SelectionBound
& end
) {
2765 selection_controller_
->OnSelectionEditable(is_editable
);
2766 selection_controller_
->OnSelectionEmpty(is_empty_text_form_control
);
2767 selection_controller_
->OnSelectionBoundsChanged(start
, end
);
2770 void RenderWidgetHostViewAura::CreateSelectionController() {
2771 ui::TouchSelectionController::Config tsc_config
;
2772 tsc_config
.max_tap_duration
= base::TimeDelta::FromMilliseconds(
2773 ui::GestureConfiguration::GetInstance()->long_press_time_in_ms());
2774 tsc_config
.tap_slop
= ui::GestureConfiguration::GetInstance()
2775 ->max_touch_move_in_pixels_for_click();
2776 tsc_config
.show_on_tap_for_empty_editable
= true;
2777 tsc_config
.enable_longpress_drag_selection
= false;
2778 selection_controller_
.reset(new ui::TouchSelectionController(
2779 selection_controller_client_
.get(), tsc_config
));
2782 void RenderWidgetHostViewAura::HandleGestureForTouchSelection(
2783 ui::GestureEvent
* event
) {
2784 switch (event
->type()) {
2785 case ui::ET_GESTURE_LONG_PRESS
:
2786 if (selection_controller_
->WillHandleLongPressEvent(
2787 base::TimeTicks() + event
->time_stamp(), event
->location_f())) {
2788 event
->SetHandled();
2791 case ui::ET_GESTURE_TAP
:
2792 if (selection_controller_
->WillHandleTapEvent(event
->location_f()))
2793 event
->SetHandled();
2795 case ui::ET_GESTURE_SCROLL_BEGIN
:
2796 selection_controller_client_
->OnScrollStarted();
2798 case ui::ET_GESTURE_SCROLL_END
:
2799 selection_controller_client_
->OnScrollCompleted();
2806 ////////////////////////////////////////////////////////////////////////////////
2807 // DelegatedFrameHost, public:
2809 ui::Layer
* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const {
2810 return window_
->layer();
2813 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const {
2814 return !host_
->is_hidden();
2817 gfx::Size
RenderWidgetHostViewAura::DelegatedFrameHostDesiredSizeInDIP() const {
2818 return window_
->bounds().size();
2821 bool RenderWidgetHostViewAura::DelegatedFrameCanCreateResizeLock() const {
2822 #if !defined(OS_CHROMEOS)
2823 // On Windows and Linux, holding pointer moves will not help throttling
2825 // TODO(piman): on Windows we need to block (nested message loop?) the
2826 // WM_SIZE event. On Linux we need to throttle at the WM level using
2827 // _NET_WM_SYNC_REQUEST.
2830 if (host_
->auto_resize_enabled())
2836 scoped_ptr
<ResizeLock
>
2837 RenderWidgetHostViewAura::DelegatedFrameHostCreateResizeLock(
2838 bool defer_compositor_lock
) {
2839 gfx::Size desired_size
= window_
->bounds().size();
2840 return scoped_ptr
<ResizeLock
>(new CompositorResizeLock(
2843 defer_compositor_lock
,
2844 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs
)));
2847 void RenderWidgetHostViewAura::DelegatedFrameHostResizeLockWasReleased() {
2848 host_
->WasResized();
2851 void RenderWidgetHostViewAura::DelegatedFrameHostSendCompositorSwapAck(
2852 int output_surface_id
,
2853 const cc::CompositorFrameAck
& ack
) {
2854 host_
->Send(new ViewMsg_SwapCompositorFrameAck(host_
->GetRoutingID(),
2855 output_surface_id
, ack
));
2858 void RenderWidgetHostViewAura::DelegatedFrameHostSendReclaimCompositorResources(
2859 int output_surface_id
,
2860 const cc::CompositorFrameAck
& ack
) {
2861 host_
->Send(new ViewMsg_ReclaimCompositorResources(host_
->GetRoutingID(),
2862 output_surface_id
, ack
));
2865 void RenderWidgetHostViewAura::DelegatedFrameHostOnLostCompositorResources() {
2866 host_
->ScheduleComposite();
2869 void RenderWidgetHostViewAura::DelegatedFrameHostUpdateVSyncParameters(
2870 const base::TimeTicks
& timebase
,
2871 const base::TimeDelta
& interval
) {
2872 host_
->UpdateVSyncParameters(timebase
, interval
);
2875 void RenderWidgetHostViewAura::OnDidNavigateMainFrameToNewPage() {
2876 ui::GestureRecognizer::Get()->CancelActiveTouches(window_
);
2879 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() {
2880 return delegated_frame_host_
->GetSurfaceIdNamespace();
2883 ////////////////////////////////////////////////////////////////////////////////
2884 // RenderWidgetHostViewBase, public:
2887 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo
* results
) {
2888 GetScreenInfoForWindow(results
, NULL
);
2891 } // namespace content