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/web_input_event_util.h"
34 #include "content/browser/renderer_host/overscroll_controller.h"
35 #include "content/browser/renderer_host/render_view_host_delegate.h"
36 #include "content/browser/renderer_host/render_view_host_delegate_view.h"
37 #include "content/browser/renderer_host/render_view_host_impl.h"
38 #include "content/browser/renderer_host/render_widget_host_impl.h"
39 #include "content/browser/renderer_host/ui_events_helper.h"
40 #include "content/browser/renderer_host/web_input_event_aura.h"
41 #include "content/common/gpu/client/gl_helper.h"
42 #include "content/common/gpu/gpu_messages.h"
43 #include "content/common/view_messages.h"
44 #include "content/public/browser/content_browser_client.h"
45 #include "content/public/browser/overscroll_configuration.h"
46 #include "content/public/browser/render_view_host.h"
47 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
48 #include "content/public/browser/user_metrics.h"
49 #include "content/public/common/content_switches.h"
50 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
51 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
52 #include "third_party/WebKit/public/web/WebInputEvent.h"
53 #include "ui/aura/client/aura_constants.h"
54 #include "ui/aura/client/cursor_client.h"
55 #include "ui/aura/client/cursor_client_observer.h"
56 #include "ui/aura/client/focus_client.h"
57 #include "ui/aura/client/screen_position_client.h"
58 #include "ui/aura/client/window_tree_client.h"
59 #include "ui/aura/env.h"
60 #include "ui/aura/window.h"
61 #include "ui/aura/window_event_dispatcher.h"
62 #include "ui/aura/window_observer.h"
63 #include "ui/aura/window_tracker.h"
64 #include "ui/aura/window_tree_host.h"
65 #include "ui/base/clipboard/scoped_clipboard_writer.h"
66 #include "ui/base/hit_test.h"
67 #include "ui/base/ime/input_method.h"
68 #include "ui/base/ui_base_types.h"
69 #include "ui/compositor/compositor_vsync_manager.h"
70 #include "ui/compositor/dip_util.h"
71 #include "ui/events/blink/blink_event_util.h"
72 #include "ui/events/event.h"
73 #include "ui/events/event_utils.h"
74 #include "ui/events/gestures/gesture_recognizer.h"
75 #include "ui/gfx/canvas.h"
76 #include "ui/gfx/display.h"
77 #include "ui/gfx/geometry/rect_conversions.h"
78 #include "ui/gfx/geometry/size_conversions.h"
79 #include "ui/gfx/screen.h"
80 #include "ui/gfx/skia_util.h"
81 #include "ui/wm/public/activation_client.h"
82 #include "ui/wm/public/scoped_tooltip_disabler.h"
83 #include "ui/wm/public/tooltip_client.h"
84 #include "ui/wm/public/transient_window_client.h"
85 #include "ui/wm/public/window_types.h"
88 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
89 #include "content/browser/accessibility/browser_accessibility_win.h"
90 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
91 #include "content/common/plugin_constants_win.h"
92 #include "ui/base/win/hidden_window.h"
93 #include "ui/gfx/gdi_util.h"
94 #include "ui/gfx/win/dpi.h"
97 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
98 #include "content/common/input_messages.h"
99 #include "ui/events/linux/text_edit_command_auralinux.h"
100 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
103 using gfx::RectToSkIRect
;
104 using gfx::SkIRectToRect
;
106 using blink::WebScreenInfo
;
107 using blink::WebInputEvent
;
108 using blink::WebGestureEvent
;
109 using blink::WebTouchEvent
;
115 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting
116 // the border of the view, in order to get valid movement information. However,
117 // forcing the cursor back to the center of the view after each mouse move
118 // doesn't work well. It reduces the frequency of useful mouse move messages
119 // significantly. Therefore, we move the cursor to the center of the view only
120 // if it approaches the border. |kMouseLockBorderPercentage| specifies the width
121 // of the border area, in percentage of the corresponding dimension.
122 const int kMouseLockBorderPercentage
= 15;
124 // When accelerated compositing is enabled and a widget resize is pending,
125 // we delay further resizes of the UI. The following constant is the maximum
126 // length of time that we should delay further UI resizes while waiting for a
127 // resized frame from a renderer.
128 const int kResizeLockTimeoutMs
= 67;
131 // Used to associate a plugin HWND with its RenderWidgetHostViewAura instance.
132 const wchar_t kWidgetOwnerProperty
[] = L
"RenderWidgetHostViewAuraOwner";
134 BOOL CALLBACK
WindowDestroyingCallback(HWND window
, LPARAM param
) {
135 RenderWidgetHostViewAura
* widget
=
136 reinterpret_cast<RenderWidgetHostViewAura
*>(param
);
137 if (GetProp(window
, kWidgetOwnerProperty
) == widget
) {
138 // Properties set on HWNDs must be removed to avoid leaks.
139 RemoveProp(window
, kWidgetOwnerProperty
);
140 RenderWidgetHostViewBase::DetachPluginWindowsCallback(window
);
145 BOOL CALLBACK
HideWindowsCallback(HWND window
, LPARAM param
) {
146 RenderWidgetHostViewAura
* widget
=
147 reinterpret_cast<RenderWidgetHostViewAura
*>(param
);
148 if (GetProp(window
, kWidgetOwnerProperty
) == widget
)
149 SetParent(window
, ui::GetHiddenWindow());
153 BOOL CALLBACK
ShowWindowsCallback(HWND window
, LPARAM param
) {
154 RenderWidgetHostViewAura
* widget
=
155 reinterpret_cast<RenderWidgetHostViewAura
*>(param
);
157 if (GetProp(window
, kWidgetOwnerProperty
) == widget
&&
158 widget
->GetNativeView()->GetHost()) {
159 HWND parent
= widget
->GetNativeView()->GetHost()->GetAcceleratedWidget();
160 SetParent(window
, parent
);
165 struct CutoutRectsParams
{
166 RenderWidgetHostViewAura
* widget
;
167 std::vector
<gfx::Rect
> cutout_rects
;
168 std::map
<HWND
, WebPluginGeometry
>* geometry
;
171 // Used to update the region for the windowed plugin to draw in. We start with
172 // the clip rect from the renderer, then remove the cutout rects from the
173 // renderer, and then remove the transient windows from the root window and the
174 // constrained windows from the parent window.
175 BOOL CALLBACK
SetCutoutRectsCallback(HWND window
, LPARAM param
) {
176 CutoutRectsParams
* params
= reinterpret_cast<CutoutRectsParams
*>(param
);
178 if (GetProp(window
, kWidgetOwnerProperty
) == params
->widget
) {
179 // First calculate the offset of this plugin from the root window, since
180 // the cutouts are relative to the root window.
182 params
->widget
->GetNativeView()->GetHost()->GetAcceleratedWidget();
184 offset
.x
= offset
.y
= 0;
185 MapWindowPoints(window
, parent
, &offset
, 1);
187 // Now get the cached clip rect and cutouts for this plugin window that came
188 // from the renderer.
189 std::map
<HWND
, WebPluginGeometry
>::iterator i
= params
->geometry
->begin();
190 while (i
!= params
->geometry
->end() &&
191 i
->second
.window
!= window
&&
192 GetParent(i
->second
.window
) != window
) {
196 if (i
== params
->geometry
->end()) {
201 HRGN hrgn
= CreateRectRgn(i
->second
.clip_rect
.x(),
202 i
->second
.clip_rect
.y(),
203 i
->second
.clip_rect
.right(),
204 i
->second
.clip_rect
.bottom());
205 // We start with the cutout rects that came from the renderer, then add the
206 // ones that came from transient and constrained windows.
207 std::vector
<gfx::Rect
> cutout_rects
= i
->second
.cutout_rects
;
208 for (size_t i
= 0; i
< params
->cutout_rects
.size(); ++i
) {
209 gfx::Rect offset_cutout
= params
->cutout_rects
[i
];
210 offset_cutout
.Offset(-offset
.x
, -offset
.y
);
211 cutout_rects
.push_back(offset_cutout
);
213 gfx::SubtractRectanglesFromRegion(hrgn
, cutout_rects
);
214 // If we don't have any cutout rects then no point in messing with the
216 if (cutout_rects
.size())
217 SetWindowRgn(window
, hrgn
, TRUE
);
222 // A callback function for EnumThreadWindows to enumerate and dismiss
223 // any owned popup windows.
224 BOOL CALLBACK
DismissOwnedPopups(HWND window
, LPARAM arg
) {
225 const HWND toplevel_hwnd
= reinterpret_cast<HWND
>(arg
);
227 if (::IsWindowVisible(window
)) {
228 const HWND owner
= ::GetWindow(window
, GW_OWNER
);
229 if (toplevel_hwnd
== owner
) {
230 ::PostMessage(window
, WM_CANCELMODE
, 0, 0);
238 // We don't mark these as handled so that they're sent back to the
239 // DefWindowProc so it can generate WM_APPCOMMAND as necessary.
240 bool IsXButtonUpEvent(const ui::MouseEvent
* event
) {
242 switch (event
->native_event().message
) {
251 void GetScreenInfoForWindow(WebScreenInfo
* results
, aura::Window
* window
) {
252 const gfx::Display display
= window
?
253 gfx::Screen::GetScreenFor(window
)->GetDisplayNearestWindow(window
) :
254 gfx::Screen::GetScreenFor(window
)->GetPrimaryDisplay();
255 results
->rect
= display
.bounds();
256 results
->availableRect
= display
.work_area();
257 // TODO(derat|oshima): Don't hardcode this. Get this from display object.
259 results
->depthPerComponent
= 8;
260 results
->deviceScaleFactor
= display
.device_scale_factor();
262 // The Display rotation and the WebScreenInfo orientation are not the same
263 // angle. The former is the physical display rotation while the later is the
264 // rotation required by the content to be shown properly on the screen, in
265 // other words, relative to the physical display.
266 results
->orientationAngle
= display
.RotationAsDegree();
267 if (results
->orientationAngle
== 90)
268 results
->orientationAngle
= 270;
269 else if (results
->orientationAngle
== 270)
270 results
->orientationAngle
= 90;
272 results
->orientationType
=
273 RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display
);
276 bool IsFractionalScaleFactor(float scale_factor
) {
277 return (scale_factor
- static_cast<int>(scale_factor
)) > 0;
280 // Reset unchanged touch point to StateStationary for touchmove and
282 void MarkUnchangedTouchPointsAsStationary(
283 blink::WebTouchEvent
* event
,
284 int changed_touch_id
) {
285 if (event
->type
== blink::WebInputEvent::TouchMove
||
286 event
->type
== blink::WebInputEvent::TouchCancel
) {
287 for (size_t i
= 0; i
< event
->touchesLength
; ++i
) {
288 if (event
->touches
[i
].id
!= changed_touch_id
)
289 event
->touches
[i
].state
= blink::WebTouchPoint::StateStationary
;
296 // We need to watch for mouse events outside a Web Popup or its parent
297 // and dismiss the popup for certain events.
298 class RenderWidgetHostViewAura::EventFilterForPopupExit
299 : public ui::EventHandler
{
301 explicit EventFilterForPopupExit(RenderWidgetHostViewAura
* rwhva
)
304 aura::Env::GetInstance()->AddPreTargetHandler(this);
307 ~EventFilterForPopupExit() override
{
308 aura::Env::GetInstance()->RemovePreTargetHandler(this);
311 // Overridden from ui::EventHandler
312 void OnMouseEvent(ui::MouseEvent
* event
) override
{
313 rwhva_
->ApplyEventFilterForPopupExit(event
);
316 void OnTouchEvent(ui::TouchEvent
* event
) override
{
317 rwhva_
->ApplyEventFilterForPopupExit(event
);
321 RenderWidgetHostViewAura
* rwhva_
;
323 DISALLOW_COPY_AND_ASSIGN(EventFilterForPopupExit
);
326 void RenderWidgetHostViewAura::ApplyEventFilterForPopupExit(
327 ui::LocatedEvent
* event
) {
328 if (in_shutdown_
|| is_fullscreen_
|| !event
->target())
331 if (event
->type() != ui::ET_MOUSE_PRESSED
&&
332 event
->type() != ui::ET_TOUCH_PRESSED
) {
336 aura::Window
* target
= static_cast<aura::Window
*>(event
->target());
337 if (target
!= window_
&&
338 (!popup_parent_host_view_
||
339 target
!= popup_parent_host_view_
->window_
)) {
340 // If we enter this code path it means that we did not receive any focus
341 // lost notifications for the popup window. Ensure that blink is aware
342 // of the fact that focus was lost for the host window by sending a Blur
344 if (popup_parent_host_view_
&& popup_parent_host_view_
->host_
)
345 popup_parent_host_view_
->host_
->Blur();
346 // Note: popup_parent_host_view_ may be NULL when there are multiple
347 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup().
352 // We have to implement the WindowObserver interface on a separate object
353 // because clang doesn't like implementing multiple interfaces that have
354 // methods with the same name. This object is owned by the
355 // RenderWidgetHostViewAura.
356 class RenderWidgetHostViewAura::WindowObserver
: public aura::WindowObserver
{
358 explicit WindowObserver(RenderWidgetHostViewAura
* view
)
360 view_
->window_
->AddObserver(this);
363 ~WindowObserver() override
{ view_
->window_
->RemoveObserver(this); }
365 // Overridden from aura::WindowObserver:
366 void OnWindowAddedToRootWindow(aura::Window
* window
) override
{
367 if (window
== view_
->window_
)
368 view_
->AddedToRootWindow();
371 void OnWindowRemovingFromRootWindow(aura::Window
* window
,
372 aura::Window
* new_root
) override
{
373 if (window
== view_
->window_
)
374 view_
->RemovingFromRootWindow();
377 void OnWindowHierarchyChanged(const HierarchyChangeParams
& params
) override
{
378 view_
->ParentHierarchyChanged();
382 RenderWidgetHostViewAura
* view_
;
384 DISALLOW_COPY_AND_ASSIGN(WindowObserver
);
387 // This class provides functionality to observe the ancestors of the RWHVA for
388 // bounds changes. This is done to snap the RWHVA window to a pixel boundary,
389 // which could change when the bounds relative to the root changes.
390 // An example where this happens is below:-
391 // The fast resize code path for bookmarks where in the parent of RWHVA which
392 // is WCV has its bounds changed before the bookmark is hidden. This results in
393 // the traditional bounds change notification for the WCV reporting the old
394 // bounds as the bookmark is still around. Observing all the ancestors of the
395 // RWHVA window enables us to know when the bounds of the window relative to
396 // root changes and allows us to snap accordingly.
397 class RenderWidgetHostViewAura::WindowAncestorObserver
398 : public aura::WindowObserver
{
400 explicit WindowAncestorObserver(RenderWidgetHostViewAura
* view
)
402 aura::Window
* parent
= view_
->window_
->parent();
404 parent
->AddObserver(this);
405 ancestors_
.insert(parent
);
406 parent
= parent
->parent();
410 ~WindowAncestorObserver() override
{
411 RemoveAncestorObservers();
414 void OnWindowBoundsChanged(aura::Window
* window
,
415 const gfx::Rect
& old_bounds
,
416 const gfx::Rect
& new_bounds
) override
{
417 DCHECK(ancestors_
.find(window
) != ancestors_
.end());
418 if (new_bounds
.origin() != old_bounds
.origin())
419 view_
->HandleParentBoundsChanged();
423 void RemoveAncestorObservers() {
424 for (auto ancestor
: ancestors_
)
425 ancestor
->RemoveObserver(this);
429 RenderWidgetHostViewAura
* view_
;
430 std::set
<aura::Window
*> ancestors_
;
432 DISALLOW_COPY_AND_ASSIGN(WindowAncestorObserver
);
435 ////////////////////////////////////////////////////////////////////////////////
436 // RenderWidgetHostViewAura, public:
438 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost
* host
,
439 bool is_guest_view_hack
)
440 : host_(RenderWidgetHostImpl::From(host
)),
441 window_(new aura::Window(this)),
442 delegated_frame_host_(new DelegatedFrameHost(this)),
444 in_bounds_changed_(false),
445 is_fullscreen_(false),
446 popup_parent_host_view_(NULL
),
447 popup_child_host_view_(NULL
),
449 text_input_type_(ui::TEXT_INPUT_TYPE_NONE
),
450 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT
),
451 text_input_flags_(0),
452 can_compose_inline_(true),
453 has_composition_text_(false),
454 accept_return_character_(false),
455 last_swapped_software_frame_scale_factor_(1.f
),
457 synthetic_move_sent_(false),
458 cursor_visibility_state_in_renderer_(UNKNOWN
),
460 legacy_render_widget_host_HWND_(NULL
),
461 legacy_window_destroyed_(false),
462 showing_context_menu_(false),
464 has_snapped_to_boundary_(false),
465 touch_editing_client_(NULL
),
466 is_guest_view_hack_(is_guest_view_hack
),
467 begin_frame_observer_proxy_(this),
468 weak_ptr_factory_(this) {
469 if (!is_guest_view_hack_
)
470 host_
->SetView(this);
472 window_observer_
.reset(new WindowObserver(this));
474 aura::client::SetTooltipText(window_
, &tooltip_
);
475 aura::client::SetActivationDelegate(window_
, this);
476 aura::client::SetFocusChangeObserver(window_
, this);
477 window_
->set_layer_owner_delegate(delegated_frame_host_
.get());
478 gfx::Screen::GetScreenFor(window_
)->AddObserver(this);
480 bool overscroll_enabled
= base::CommandLine::ForCurrentProcess()->
481 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation
) != "0";
482 SetOverscrollControllerEnabled(overscroll_enabled
);
485 ////////////////////////////////////////////////////////////////////////////////
486 // RenderWidgetHostViewAura, RenderWidgetHostView implementation:
488 bool RenderWidgetHostViewAura::OnMessageReceived(
489 const IPC::Message
& message
) {
491 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewAura
, message
)
492 // TODO(kevers): Move to RenderWidgetHostViewImpl and consolidate IPC
493 // messages for TextInput<State|Type>Changed. Corresponding code in
494 // RenderWidgetHostViewAndroid should also be moved at the same time.
495 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged
,
496 OnTextInputStateChanged
)
497 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames
,
498 OnSetNeedsBeginFrames
)
499 IPC_MESSAGE_UNHANDLED(handled
= false)
500 IPC_END_MESSAGE_MAP()
504 void RenderWidgetHostViewAura::InitAsChild(
505 gfx::NativeView parent_view
) {
506 window_
->SetType(ui::wm::WINDOW_TYPE_CONTROL
);
507 window_
->Init(ui::LAYER_SOLID_COLOR
);
508 window_
->SetName("RenderWidgetHostViewAura");
509 window_
->layer()->SetColor(background_color_
);
512 void RenderWidgetHostViewAura::InitAsPopup(
513 RenderWidgetHostView
* parent_host_view
,
514 const gfx::Rect
& bounds_in_screen
) {
515 popup_parent_host_view_
=
516 static_cast<RenderWidgetHostViewAura
*>(parent_host_view
);
518 // TransientWindowClient may be NULL during tests.
519 aura::client::TransientWindowClient
* transient_window_client
=
520 aura::client::GetTransientWindowClient();
521 RenderWidgetHostViewAura
* old_child
=
522 popup_parent_host_view_
->popup_child_host_view_
;
524 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or
525 // similar mechanism to ensure a second popup doesn't cause the first one
526 // to never get a chance to filter events. See crbug.com/160589.
527 DCHECK(old_child
->popup_parent_host_view_
== popup_parent_host_view_
);
528 if (transient_window_client
) {
529 transient_window_client
->RemoveTransientChild(
530 popup_parent_host_view_
->window_
, old_child
->window_
);
532 old_child
->popup_parent_host_view_
= NULL
;
534 popup_parent_host_view_
->popup_child_host_view_
= this;
535 window_
->SetType(ui::wm::WINDOW_TYPE_MENU
);
536 window_
->Init(ui::LAYER_SOLID_COLOR
);
537 window_
->SetName("RenderWidgetHostViewAura");
538 window_
->layer()->SetColor(background_color_
);
540 // Setting the transient child allows for the popup to get mouse events when
541 // in a system modal dialog. Do this before calling ParentWindowWithContext
542 // below so that the transient parent is visible to WindowTreeClient.
543 // This fixes crbug.com/328593.
544 if (transient_window_client
) {
545 transient_window_client
->AddTransientChild(
546 popup_parent_host_view_
->window_
, window_
);
549 aura::Window
* root
= popup_parent_host_view_
->window_
->GetRootWindow();
550 aura::client::ParentWindowWithContext(window_
, root
, bounds_in_screen
);
552 SetBounds(bounds_in_screen
);
554 if (NeedsMouseCapture())
555 window_
->SetCapture();
557 event_filter_for_popup_exit_
.reset(new EventFilterForPopupExit(this));
560 void RenderWidgetHostViewAura::InitAsFullscreen(
561 RenderWidgetHostView
* reference_host_view
) {
562 is_fullscreen_
= true;
563 window_
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
564 window_
->Init(ui::LAYER_SOLID_COLOR
);
565 window_
->SetName("RenderWidgetHostViewAura");
566 window_
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
567 window_
->layer()->SetColor(background_color_
);
569 aura::Window
* parent
= NULL
;
571 if (reference_host_view
) {
572 aura::Window
* reference_window
=
573 static_cast<RenderWidgetHostViewAura
*>(reference_host_view
)->window_
;
574 if (reference_window
) {
575 host_tracker_
.reset(new aura::WindowTracker
);
576 host_tracker_
->Add(reference_window
);
578 gfx::Display display
= gfx::Screen::GetScreenFor(window_
)->
579 GetDisplayNearestWindow(reference_window
);
580 parent
= reference_window
->GetRootWindow();
581 bounds
= display
.bounds();
583 aura::client::ParentWindowWithContext(window_
, parent
, bounds
);
588 RenderWidgetHost
* RenderWidgetHostViewAura::GetRenderWidgetHost() const {
592 void RenderWidgetHostViewAura::Show() {
596 if (!host_
->is_hidden())
599 bool has_saved_frame
= delegated_frame_host_
->HasSavedFrame();
600 ui::LatencyInfo renderer_latency_info
, browser_latency_info
;
601 if (has_saved_frame
) {
602 browser_latency_info
.AddLatencyNumber(
603 ui::TAB_SHOW_COMPONENT
, host_
->GetLatencyComponentId(), 0);
605 renderer_latency_info
.AddLatencyNumber(
606 ui::TAB_SHOW_COMPONENT
, host_
->GetLatencyComponentId(), 0);
608 host_
->WasShown(renderer_latency_info
);
610 aura::Window
* root
= window_
->GetRootWindow();
612 aura::client::CursorClient
* cursor_client
=
613 aura::client::GetCursorClient(root
);
615 NotifyRendererOfCursorVisibilityState(cursor_client
->IsCursorVisible());
618 delegated_frame_host_
->WasShown(browser_latency_info
);
621 if (legacy_render_widget_host_HWND_
) {
622 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent
623 // window before reparenting any plugins. This ensures that the plugin
624 // windows stay on top of the child Zorder in the parent and receive
625 // mouse events, etc.
626 legacy_render_widget_host_HWND_
->UpdateParent(
627 GetNativeView()->GetHost()->GetAcceleratedWidget());
628 legacy_render_widget_host_HWND_
->SetBounds(
629 window_
->GetBoundsInRootWindow());
631 LPARAM lparam
= reinterpret_cast<LPARAM
>(this);
632 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback
, lparam
);
634 if (legacy_render_widget_host_HWND_
)
635 legacy_render_widget_host_HWND_
->Show();
639 void RenderWidgetHostViewAura::Hide() {
642 if (host_
&& !host_
->is_hidden()) {
644 delegated_frame_host_
->WasHidden();
647 constrained_rects_
.clear();
648 aura::WindowTreeHost
* host
= window_
->GetHost();
650 HWND parent
= host
->GetAcceleratedWidget();
651 LPARAM lparam
= reinterpret_cast<LPARAM
>(this);
652 EnumChildWindows(parent
, HideWindowsCallback
, lparam
);
653 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
654 // hidden window on the same lines as Windowed plugin windows.
655 if (legacy_render_widget_host_HWND_
)
656 legacy_render_widget_host_HWND_
->UpdateParent(ui::GetHiddenWindow());
662 if (legacy_render_widget_host_HWND_
)
663 legacy_render_widget_host_HWND_
->Hide();
667 void RenderWidgetHostViewAura::SetSize(const gfx::Size
& size
) {
668 // For a SetSize operation, we don't care what coordinate system the origin
669 // of the window is in, it's only important to make sure that the origin
670 // remains constant after the operation.
671 InternalSetBounds(gfx::Rect(window_
->bounds().origin(), size
));
674 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect
& rect
) {
675 gfx::Point
relative_origin(rect
.origin());
677 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but
678 // Window::SetBounds() takes parent coordinates, so do the conversion here.
679 aura::Window
* root
= window_
->GetRootWindow();
681 aura::client::ScreenPositionClient
* screen_position_client
=
682 aura::client::GetScreenPositionClient(root
);
683 if (screen_position_client
) {
684 screen_position_client
->ConvertPointFromScreen(
685 window_
->parent(), &relative_origin
);
689 InternalSetBounds(gfx::Rect(relative_origin
, rect
.size()));
692 gfx::Vector2dF
RenderWidgetHostViewAura::GetLastScrollOffset() const {
693 return last_scroll_offset_
;
696 gfx::NativeView
RenderWidgetHostViewAura::GetNativeView() const {
700 gfx::NativeViewId
RenderWidgetHostViewAura::GetNativeViewId() const {
702 aura::WindowTreeHost
* host
= window_
->GetHost();
704 return reinterpret_cast<gfx::NativeViewId
>(host
->GetAcceleratedWidget());
706 return static_cast<gfx::NativeViewId
>(NULL
);
709 gfx::NativeViewAccessible
RenderWidgetHostViewAura::GetNativeViewAccessible() {
711 aura::WindowTreeHost
* host
= window_
->GetHost();
713 return static_cast<gfx::NativeViewAccessible
>(NULL
);
714 BrowserAccessibilityManager
* manager
=
715 host_
->GetOrCreateRootBrowserAccessibilityManager();
717 return manager
->GetRoot()->ToBrowserAccessibilityWin();
721 return static_cast<gfx::NativeViewAccessible
>(NULL
);
724 ui::TextInputClient
* RenderWidgetHostViewAura::GetTextInputClient() {
728 void RenderWidgetHostViewAura::OnSetNeedsBeginFrames(bool needs_begin_frames
) {
729 begin_frame_observer_proxy_
.SetNeedsBeginFrames(needs_begin_frames
);
732 void RenderWidgetHostViewAura::SendBeginFrame(const cc::BeginFrameArgs
& args
) {
733 delegated_frame_host_
->SetVSyncParameters(args
.frame_time
, args
.interval
);
734 host_
->Send(new ViewMsg_BeginFrame(host_
->GetRoutingID(), args
));
737 void RenderWidgetHostViewAura::SetKeyboardFocus() {
740 aura::WindowTreeHost
* host
= window_
->GetHost();
742 ::SetFocus(host
->GetAcceleratedWidget());
747 RenderFrameHostImpl
* RenderWidgetHostViewAura::GetFocusedFrame() {
748 if (!host_
->IsRenderView())
750 RenderViewHost
* rvh
= RenderViewHost::From(host_
);
751 FrameTreeNode
* focused_frame
=
752 rvh
->GetDelegate()->GetFrameTree()->GetFocusedFrame();
756 return focused_frame
->current_frame_host();
759 bool RenderWidgetHostViewAura::CanRendererHandleEvent(
760 const ui::MouseEvent
* event
,
762 bool selection_popup
) {
764 bool showing_context_menu
= showing_context_menu_
;
765 showing_context_menu_
= false;
768 if (event
->type() == ui::ET_MOUSE_CAPTURE_CHANGED
)
771 if ((mouse_locked
|| selection_popup
) &&
772 (event
->type() == ui::ET_MOUSE_EXITED
))
776 // Don't forward the mouse leave message which is received when the context
777 // menu is displayed by the page. This confuses the page and causes state
779 if (showing_context_menu
) {
780 if (event
->type() == ui::ET_MOUSE_EXITED
)
783 // Renderer cannot handle WM_XBUTTON or NC events.
784 switch (event
->native_event().message
) {
787 case WM_XBUTTONDBLCLK
:
788 case WM_NCMOUSELEAVE
:
790 case WM_NCLBUTTONDOWN
:
792 case WM_NCLBUTTONDBLCLK
:
793 case WM_NCRBUTTONDOWN
:
795 case WM_NCRBUTTONDBLCLK
:
796 case WM_NCMBUTTONDOWN
:
798 case WM_NCMBUTTONDBLCLK
:
799 case WM_NCXBUTTONDOWN
:
801 case WM_NCXBUTTONDBLCLK
:
806 #elif defined(USE_X11)
807 // Renderer only supports standard mouse buttons, so ignore programmable
809 switch (event
->type()) {
810 case ui::ET_MOUSE_PRESSED
:
811 case ui::ET_MOUSE_RELEASED
: {
812 const int kAllowedButtons
= ui::EF_LEFT_MOUSE_BUTTON
|
813 ui::EF_MIDDLE_MOUSE_BUTTON
|
814 ui::EF_RIGHT_MOUSE_BUTTON
;
815 return (event
->flags() & kAllowedButtons
) != 0;
824 void RenderWidgetHostViewAura::HandleParentBoundsChanged() {
825 SnapToPhysicalPixelBoundary();
827 if (legacy_render_widget_host_HWND_
) {
828 legacy_render_widget_host_HWND_
->SetBounds(
829 window_
->GetBoundsInRootWindow());
833 host_
->SendScreenRects();
836 void RenderWidgetHostViewAura::ParentHierarchyChanged() {
837 ancestor_window_observer_
.reset(new WindowAncestorObserver(this));
838 // Snap when we receive a hierarchy changed. http://crbug.com/388908.
839 HandleParentBoundsChanged();
842 void RenderWidgetHostViewAura::MovePluginWindows(
843 const std::vector
<WebPluginGeometry
>& plugin_window_moves
) {
845 // We need to clip the rectangle to the tab's viewport, otherwise we will draw
846 // over the browser UI.
847 if (!window_
->GetRootWindow()) {
848 DCHECK(plugin_window_moves
.empty());
851 HWND parent
= window_
->GetHost()->GetAcceleratedWidget();
852 gfx::Rect view_bounds
= window_
->GetBoundsInRootWindow();
853 std::vector
<WebPluginGeometry
> moves
= plugin_window_moves
;
855 gfx::Rect
view_port(view_bounds
.size());
857 for (size_t i
= 0; i
< moves
.size(); ++i
) {
858 gfx::Rect
clip(moves
[i
].clip_rect
);
859 gfx::Vector2d
view_port_offset(
860 moves
[i
].window_rect
.OffsetFromOrigin());
861 clip
.Offset(view_port_offset
);
862 clip
.Intersect(view_port
);
863 clip
.Offset(-view_port_offset
);
864 moves
[i
].clip_rect
= clip
;
866 moves
[i
].window_rect
.Offset(view_bounds
.OffsetFromOrigin());
868 plugin_window_moves_
[moves
[i
].window
] = moves
[i
];
870 // constrained_rects_ are relative to the root window. We want to convert
871 // them to be relative to the plugin window.
872 for (size_t j
= 0; j
< constrained_rects_
.size(); ++j
) {
873 gfx::Rect offset_cutout
= constrained_rects_
[j
];
874 offset_cutout
-= moves
[i
].window_rect
.OffsetFromOrigin();
875 moves
[i
].cutout_rects
.push_back(offset_cutout
);
879 MovePluginWindowsHelper(parent
, moves
);
881 // Make sure each plugin window (or its wrapper if it exists) has a pointer to
883 for (size_t i
= 0; i
< moves
.size(); ++i
) {
884 HWND window
= moves
[i
].window
;
885 if (GetParent(window
) != parent
) {
886 window
= GetParent(window
);
888 if (!GetProp(window
, kWidgetOwnerProperty
))
889 SetProp(window
, kWidgetOwnerProperty
, this);
891 #endif // defined(OS_WIN)
894 void RenderWidgetHostViewAura::Focus() {
895 // Make sure we have a FocusClient before attempting to Focus(). In some
896 // situations we may not yet be in a valid Window hierarchy (such as reloading
897 // after out of memory discarded the tab).
898 aura::client::FocusClient
* client
= aura::client::GetFocusClient(window_
);
903 bool RenderWidgetHostViewAura::HasFocus() const {
904 return window_
->HasFocus();
907 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const {
908 return delegated_frame_host_
->CanCopyToBitmap();
911 bool RenderWidgetHostViewAura::IsShowing() {
912 return window_
->IsVisible();
915 gfx::Rect
RenderWidgetHostViewAura::GetViewBounds() const {
916 return window_
->GetBoundsInScreen();
919 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color
) {
920 RenderWidgetHostViewBase::SetBackgroundColor(color
);
921 bool opaque
= GetBackgroundOpaque();
922 host_
->SetBackgroundOpaque(opaque
);
923 window_
->layer()->SetFillsBoundsOpaquely(opaque
);
924 window_
->layer()->SetColor(color
);
927 gfx::Size
RenderWidgetHostViewAura::GetVisibleViewportSize() const {
928 gfx::Rect
requested_rect(GetRequestedRendererSize());
929 requested_rect
.Inset(insets_
);
930 return requested_rect
.size();
933 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets
& insets
) {
934 if (insets
!= insets_
) {
940 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor
& cursor
) {
941 current_cursor_
= cursor
;
942 const gfx::Display display
= gfx::Screen::GetScreenFor(window_
)->
943 GetDisplayNearestWindow(window_
);
944 current_cursor_
.SetDisplayInfo(display
);
945 UpdateCursorIfOverSelf();
948 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading
) {
949 is_loading_
= is_loading
;
950 UpdateCursorIfOverSelf();
953 void RenderWidgetHostViewAura::TextInputTypeChanged(
954 ui::TextInputType type
,
955 ui::TextInputMode input_mode
,
956 bool can_compose_inline
,
958 if (text_input_type_
!= type
||
959 text_input_mode_
!= input_mode
||
960 can_compose_inline_
!= can_compose_inline
||
961 text_input_flags_
!= flags
) {
962 text_input_type_
= type
;
963 text_input_mode_
= input_mode
;
964 can_compose_inline_
= can_compose_inline
;
965 text_input_flags_
= flags
;
966 if (GetInputMethod())
967 GetInputMethod()->OnTextInputTypeChanged(this);
968 if (touch_editing_client_
)
969 touch_editing_client_
->OnTextInputTypeChanged(text_input_type_
);
973 void RenderWidgetHostViewAura::OnTextInputStateChanged(
974 const ViewHostMsg_TextInputState_Params
& params
) {
975 text_input_flags_
= params
.flags
;
976 if (params
.show_ime_if_needed
&& params
.type
!= ui::TEXT_INPUT_TYPE_NONE
) {
977 if (GetInputMethod())
978 GetInputMethod()->ShowImeIfNeeded();
982 void RenderWidgetHostViewAura::ImeCancelComposition() {
983 if (GetInputMethod())
984 GetInputMethod()->CancelComposition(this);
985 has_composition_text_
= false;
988 void RenderWidgetHostViewAura::ImeCompositionRangeChanged(
989 const gfx::Range
& range
,
990 const std::vector
<gfx::Rect
>& character_bounds
) {
991 composition_character_bounds_
= character_bounds
;
994 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status
,
996 UpdateCursorIfOverSelf();
1000 void RenderWidgetHostViewAura::Destroy() {
1001 // Beware, this function is not called on all destruction paths. It will
1002 // implicitly end up calling ~RenderWidgetHostViewAura though, so all
1003 // destruction/cleanup code should happen there, not here.
1004 in_shutdown_
= true;
1008 void RenderWidgetHostViewAura::SetTooltipText(
1009 const base::string16
& tooltip_text
) {
1010 tooltip_
= tooltip_text
;
1011 aura::Window
* root_window
= window_
->GetRootWindow();
1012 aura::client::TooltipClient
* tooltip_client
=
1013 aura::client::GetTooltipClient(root_window
);
1014 if (tooltip_client
) {
1015 tooltip_client
->UpdateTooltip(window_
);
1016 // Content tooltips should be visible indefinitely.
1017 tooltip_client
->SetTooltipShownTimeout(window_
, 0);
1021 void RenderWidgetHostViewAura::SelectionChanged(const base::string16
& text
,
1023 const gfx::Range
& range
) {
1024 RenderWidgetHostViewBase::SelectionChanged(text
, offset
, range
);
1026 #if defined(USE_X11) && !defined(OS_CHROMEOS)
1027 if (text
.empty() || range
.is_empty())
1029 size_t pos
= range
.GetMin() - offset
;
1030 size_t n
= range
.length();
1032 DCHECK(pos
+ n
<= text
.length()) << "The text can not fully cover range.";
1033 if (pos
>= text
.length()) {
1034 NOTREACHED() << "The text can not cover range.";
1038 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
1039 ui::ScopedClipboardWriter
clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION
);
1040 clipboard_writer
.WriteText(text
.substr(pos
, n
));
1041 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
1044 gfx::Size
RenderWidgetHostViewAura::GetRequestedRendererSize() const {
1045 return delegated_frame_host_
->GetRequestedRendererSize();
1048 void RenderWidgetHostViewAura::SelectionBoundsChanged(
1049 const ViewHostMsg_SelectionBounds_Params
& params
) {
1050 ui::SelectionBound anchor_bound
, focus_bound
;
1051 anchor_bound
.SetEdge(params
.anchor_rect
.origin(),
1052 params
.anchor_rect
.bottom_left());
1053 focus_bound
.SetEdge(params
.focus_rect
.origin(),
1054 params
.focus_rect
.bottom_left());
1056 if (params
.anchor_rect
== params
.focus_rect
) {
1057 anchor_bound
.set_type(ui::SelectionBound::CENTER
);
1058 focus_bound
.set_type(ui::SelectionBound::CENTER
);
1060 // Whether text is LTR at the anchor handle.
1061 bool anchor_LTR
= params
.anchor_dir
== blink::WebTextDirectionLeftToRight
;
1062 // Whether text is LTR at the focus handle.
1063 bool focus_LTR
= params
.focus_dir
== blink::WebTextDirectionLeftToRight
;
1065 if ((params
.is_anchor_first
&& anchor_LTR
) ||
1066 (!params
.is_anchor_first
&& !anchor_LTR
)) {
1067 anchor_bound
.set_type(ui::SelectionBound::LEFT
);
1069 anchor_bound
.set_type(ui::SelectionBound::RIGHT
);
1071 if ((params
.is_anchor_first
&& focus_LTR
) ||
1072 (!params
.is_anchor_first
&& !focus_LTR
)) {
1073 focus_bound
.set_type(ui::SelectionBound::RIGHT
);
1075 focus_bound
.set_type(ui::SelectionBound::LEFT
);
1079 if (anchor_bound
== selection_anchor_
&& focus_bound
== selection_focus_
)
1082 selection_anchor_
= anchor_bound
;
1083 selection_focus_
= focus_bound
;
1084 if (GetInputMethod())
1085 GetInputMethod()->OnCaretBoundsChanged(this);
1087 if (touch_editing_client_
) {
1088 touch_editing_client_
->OnSelectionOrCursorChanged(
1089 anchor_bound
, focus_bound
);
1093 void RenderWidgetHostViewAura::CopyFromCompositingSurface(
1094 const gfx::Rect
& src_subrect
,
1095 const gfx::Size
& dst_size
,
1096 ReadbackRequestCallback
& callback
,
1097 const SkColorType preferred_color_type
) {
1098 delegated_frame_host_
->CopyFromCompositingSurface(
1099 src_subrect
, dst_size
, callback
, preferred_color_type
);
1102 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceToVideoFrame(
1103 const gfx::Rect
& src_subrect
,
1104 const scoped_refptr
<media::VideoFrame
>& target
,
1105 const base::Callback
<void(bool)>& callback
) {
1106 delegated_frame_host_
->CopyFromCompositingSurfaceToVideoFrame(
1107 src_subrect
, target
, callback
);
1110 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const {
1111 return delegated_frame_host_
->CanCopyToVideoFrame();
1114 bool RenderWidgetHostViewAura::CanSubscribeFrame() const {
1115 return delegated_frame_host_
->CanSubscribeFrame();
1118 void RenderWidgetHostViewAura::BeginFrameSubscription(
1119 scoped_ptr
<RenderWidgetHostViewFrameSubscriber
> subscriber
) {
1120 delegated_frame_host_
->BeginFrameSubscription(subscriber
.Pass());
1123 void RenderWidgetHostViewAura::EndFrameSubscription() {
1124 delegated_frame_host_
->EndFrameSubscription();
1128 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
1129 return (legacy_render_widget_host_HWND_
!= NULL
);
1132 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects(
1133 const std::vector
<gfx::Rect
>& rects
) {
1134 // Check this before setting constrained_rects_, so that next time they're set
1135 // and we have a root window we don't early return.
1136 if (!window_
->GetHost())
1139 if (rects
== constrained_rects_
)
1142 constrained_rects_
= rects
;
1144 HWND parent
= window_
->GetHost()->GetAcceleratedWidget();
1145 CutoutRectsParams params
;
1146 params
.widget
= this;
1147 params
.cutout_rects
= constrained_rects_
;
1148 params
.geometry
= &plugin_window_moves_
;
1149 LPARAM lparam
= reinterpret_cast<LPARAM
>(¶ms
);
1150 EnumChildWindows(parent
, SetCutoutRectsCallback
, lparam
);
1153 void RenderWidgetHostViewAura::UpdateMouseLockRegion() {
1154 // Clip the cursor if chrome is running on regular desktop.
1155 if (gfx::Screen::GetScreenFor(window_
) == gfx::Screen::GetNativeScreen()) {
1157 gfx::win::DIPToScreenRect(window_
->GetBoundsInScreen()).ToRECT();
1158 ::ClipCursor(&window_rect
);
1162 void RenderWidgetHostViewAura::OnLegacyWindowDestroyed() {
1163 legacy_render_widget_host_HWND_
= NULL
;
1164 legacy_window_destroyed_
= true;
1168 void RenderWidgetHostViewAura::OnSwapCompositorFrame(
1169 uint32 output_surface_id
,
1170 scoped_ptr
<cc::CompositorFrame
> frame
) {
1171 TRACE_EVENT0("content", "RenderWidgetHostViewAura::OnSwapCompositorFrame");
1173 last_scroll_offset_
= frame
->metadata
.root_scroll_offset
;
1174 if (frame
->delegated_frame_data
) {
1175 delegated_frame_host_
->SwapDelegatedFrame(
1177 frame
->delegated_frame_data
.Pass(),
1178 frame
->metadata
.device_scale_factor
,
1179 frame
->metadata
.latency_info
,
1180 &frame
->metadata
.satisfies_sequences
);
1184 if (frame
->software_frame_data
) {
1185 DLOG(ERROR
) << "Unable to use software frame in aura";
1186 bad_message::ReceivedBadMessage(host_
->GetProcess(),
1187 bad_message::RWHVA_SHARED_MEMORY
);
1192 void RenderWidgetHostViewAura::DidStopFlinging() {
1193 if (touch_editing_client_
)
1194 touch_editing_client_
->DidStopFlinging();
1198 void RenderWidgetHostViewAura::SetParentNativeViewAccessible(
1199 gfx::NativeViewAccessible accessible_parent
) {
1202 gfx::NativeViewId
RenderWidgetHostViewAura::GetParentForWindowlessPlugin()
1204 if (legacy_render_widget_host_HWND_
) {
1205 return reinterpret_cast<gfx::NativeViewId
>(
1206 legacy_render_widget_host_HWND_
->hwnd());
1212 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
1213 const gfx::Size
& desired_size
) {
1214 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
1215 // matter what is returned here as GetBackingStore is the only caller of this
1216 // method. TODO(jbates) implement this if other Aura code needs it.
1220 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo
* results
) {
1221 GetScreenInfoForWindow(results
, window_
->GetRootWindow() ? window_
: NULL
);
1224 gfx::Rect
RenderWidgetHostViewAura::GetBoundsInRootWindow() {
1225 aura::Window
* top_level
= window_
->GetToplevelWindow();
1226 gfx::Rect
bounds(top_level
->GetBoundsInScreen());
1229 // TODO(zturner,iyengar): This will break when we remove support for NPAPI and
1230 // remove the legacy hwnd, so a better fix will need to be decided when that
1232 if (UsesNativeWindowFrame()) {
1233 // aura::Window doesn't take into account non-client area of native windows
1234 // (e.g. HWNDs), so for that case ask Windows directly what the bounds are.
1235 aura::WindowTreeHost
* host
= top_level
->GetHost();
1237 return top_level
->GetBoundsInScreen();
1238 RECT window_rect
= {0};
1239 HWND hwnd
= host
->GetAcceleratedWidget();
1240 ::GetWindowRect(hwnd
, &window_rect
);
1241 bounds
= gfx::Rect(window_rect
);
1243 // Maximized windows are outdented from the work area by the frame thickness
1244 // even though this "frame" is not painted. This confuses code (and people)
1245 // that think of a maximized window as corresponding exactly to the work
1246 // area. Correct for this by subtracting the frame thickness back off.
1247 if (::IsZoomed(hwnd
)) {
1248 bounds
.Inset(GetSystemMetrics(SM_CXSIZEFRAME
),
1249 GetSystemMetrics(SM_CYSIZEFRAME
));
1251 bounds
.Inset(GetSystemMetrics(SM_CXPADDEDBORDER
),
1252 GetSystemMetrics(SM_CXPADDEDBORDER
));
1256 bounds
= gfx::win::ScreenToDIPRect(bounds
);
1262 void RenderWidgetHostViewAura::WheelEventAck(
1263 const blink::WebMouseWheelEvent
& event
,
1264 InputEventAckState ack_result
) {
1265 if (overscroll_controller_
) {
1266 overscroll_controller_
->ReceivedEventACK(
1267 event
, (INPUT_EVENT_ACK_STATE_CONSUMED
== ack_result
));
1271 void RenderWidgetHostViewAura::GestureEventAck(
1272 const blink::WebGestureEvent
& event
,
1273 InputEventAckState ack_result
) {
1274 if (touch_editing_client_
)
1275 touch_editing_client_
->GestureEventAck(event
.type
);
1277 if (overscroll_controller_
) {
1278 overscroll_controller_
->ReceivedEventACK(
1279 event
, (INPUT_EVENT_ACK_STATE_CONSUMED
== ack_result
));
1283 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
1284 const TouchEventWithLatencyInfo
& touch
,
1285 InputEventAckState ack_result
) {
1286 ScopedVector
<ui::TouchEvent
> events
;
1287 aura::WindowTreeHost
* host
= window_
->GetHost();
1288 // |host| is NULL during tests.
1292 ui::EventResult result
= (ack_result
== INPUT_EVENT_ACK_STATE_CONSUMED
)
1296 blink::WebTouchPoint::State required_state
;
1297 switch (touch
.event
.type
) {
1298 case blink::WebInputEvent::TouchStart
:
1299 required_state
= blink::WebTouchPoint::StatePressed
;
1301 case blink::WebInputEvent::TouchEnd
:
1302 required_state
= blink::WebTouchPoint::StateReleased
;
1304 case blink::WebInputEvent::TouchMove
:
1305 required_state
= blink::WebTouchPoint::StateMoved
;
1307 case blink::WebInputEvent::TouchCancel
:
1308 required_state
= blink::WebTouchPoint::StateCancelled
;
1311 required_state
= blink::WebTouchPoint::StateUndefined
;
1316 // Only send acks for one changed touch point.
1317 bool sent_ack
= false;
1318 for (size_t i
= 0; i
< touch
.event
.touchesLength
; ++i
) {
1319 if (touch
.event
.touches
[i
].state
== required_state
) {
1321 host
->dispatcher()->ProcessedTouchEvent(touch
.event
.uniqueTouchEventId
,
1328 scoped_ptr
<SyntheticGestureTarget
>
1329 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1330 return scoped_ptr
<SyntheticGestureTarget
>(
1331 new SyntheticGestureTargetAura(host_
));
1334 InputEventAckState
RenderWidgetHostViewAura::FilterInputEvent(
1335 const blink::WebInputEvent
& input_event
) {
1336 bool consumed
= false;
1337 if (input_event
.type
== WebInputEvent::GestureFlingStart
) {
1338 const WebGestureEvent
& gesture_event
=
1339 static_cast<const WebGestureEvent
&>(input_event
);
1340 // Zero-velocity touchpad flings are an Aura-specific signal that the
1341 // touchpad scroll has ended, and should not be forwarded to the renderer.
1342 if (gesture_event
.sourceDevice
== blink::WebGestureDeviceTouchpad
&&
1343 !gesture_event
.data
.flingStart
.velocityX
&&
1344 !gesture_event
.data
.flingStart
.velocityY
) {
1349 if (overscroll_controller_
)
1350 consumed
|= overscroll_controller_
->WillHandleEvent(input_event
);
1352 // Touch events should always propagate to the renderer.
1353 if (WebTouchEvent::isTouchEventType(input_event
.type
))
1354 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED
;
1356 // Reporting consumed for a fling suggests that there's now an *active* fling
1357 // that requires both animation and a fling-end notification. However, the
1358 // OverscrollController consumes a fling to stop its propagation; it doesn't
1359 // actually tick a fling animation. Report no consumer to convey this.
1360 if (consumed
&& input_event
.type
== blink::WebInputEvent::GestureFlingStart
)
1361 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
;
1363 return consumed
? INPUT_EVENT_ACK_STATE_CONSUMED
1364 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED
;
1367 BrowserAccessibilityManager
*
1368 RenderWidgetHostViewAura::CreateBrowserAccessibilityManager(
1369 BrowserAccessibilityDelegate
* delegate
) {
1370 BrowserAccessibilityManager
* manager
= NULL
;
1372 manager
= new BrowserAccessibilityManagerWin(
1373 BrowserAccessibilityManagerWin::GetEmptyDocument(), delegate
);
1375 manager
= BrowserAccessibilityManager::Create(
1376 BrowserAccessibilityManager::GetEmptyDocument(), delegate
);
1381 gfx::AcceleratedWidget
1382 RenderWidgetHostViewAura::AccessibilityGetAcceleratedWidget() {
1384 if (legacy_render_widget_host_HWND_
)
1385 return legacy_render_widget_host_HWND_
->hwnd();
1387 return gfx::kNullAcceleratedWidget
;
1390 gfx::NativeViewAccessible
1391 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() {
1393 if (legacy_render_widget_host_HWND_
)
1394 return legacy_render_widget_host_HWND_
->window_accessible();
1400 gfx::GLSurfaceHandle
RenderWidgetHostViewAura::GetCompositingSurface() {
1401 return ImageTransportFactory::GetInstance()->GetSharedSurfaceHandle();
1404 void RenderWidgetHostViewAura::ShowDisambiguationPopup(
1405 const gfx::Rect
& rect_pixels
,
1406 const SkBitmap
& zoomed_bitmap
) {
1407 RenderViewHostDelegate
* delegate
= NULL
;
1408 if (host_
->IsRenderView())
1409 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1410 // Suppress the link disambiguation popup if the virtual keyboard is currently
1411 // requested, as it doesn't interact well with the keyboard.
1412 if (delegate
&& delegate
->IsVirtualKeyboardRequested())
1415 // |target_rect| is provided in pixels, not DIPs. So we convert it to DIPs
1416 // by scaling it by the inverse of the device scale factor.
1417 gfx::RectF
screen_target_rect_f(rect_pixels
);
1418 screen_target_rect_f
.Scale(1.0f
/ current_device_scale_factor_
);
1419 disambiguation_target_rect_
= gfx::ToEnclosingRect(screen_target_rect_f
);
1421 float scale
= static_cast<float>(zoomed_bitmap
.width()) /
1422 static_cast<float>(rect_pixels
.width());
1423 gfx::Size
zoomed_size(gfx::ToCeiledSize(
1424 gfx::ScaleSize(disambiguation_target_rect_
.size(), scale
)));
1426 // Save of a copy of the |last_scroll_offset_| for comparison when the copy
1427 // callback fires, to ensure that we haven't scrolled.
1428 disambiguation_scroll_offset_
= last_scroll_offset_
;
1430 CopyFromCompositingSurface(
1431 disambiguation_target_rect_
,
1433 base::Bind(&RenderWidgetHostViewAura::DisambiguationPopupRendered
,
1434 weak_ptr_factory_
.GetWeakPtr()),
1438 void RenderWidgetHostViewAura::DisambiguationPopupRendered(
1439 const SkBitmap
& result
,
1440 ReadbackResponse response
) {
1441 if ((response
!= READBACK_SUCCESS
) ||
1442 disambiguation_scroll_offset_
!= last_scroll_offset_
)
1445 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will
1446 // actually show the disambiguation popup.
1447 RenderViewHostDelegate
* delegate
= NULL
;
1448 if (host_
->IsRenderView())
1449 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1450 RenderViewHostDelegateView
* delegate_view
= NULL
;
1452 delegate_view
= delegate
->GetDelegateView();
1453 if (delegate
->IsVirtualKeyboardRequested())
1456 if (delegate_view
) {
1457 delegate_view
->ShowDisambiguationPopup(
1458 disambiguation_target_rect_
,
1460 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationGesture
,
1461 weak_ptr_factory_
.GetWeakPtr()),
1462 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationMouse
,
1463 weak_ptr_factory_
.GetWeakPtr()));
1467 void RenderWidgetHostViewAura::HideDisambiguationPopup() {
1468 RenderViewHostDelegate
* delegate
= NULL
;
1469 if (host_
->IsRenderView())
1470 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1471 RenderViewHostDelegateView
* delegate_view
= NULL
;
1473 delegate_view
= delegate
->GetDelegateView();
1475 delegate_view
->HideDisambiguationPopup();
1478 void RenderWidgetHostViewAura::ProcessDisambiguationGesture(
1479 ui::GestureEvent
* event
) {
1480 blink::WebGestureEvent web_gesture
= content::MakeWebGestureEvent(*event
);
1481 // If we fail to make a WebGestureEvent that is a Tap from the provided event,
1482 // don't forward it to Blink.
1483 if (web_gesture
.type
< blink::WebInputEvent::Type::GestureTap
||
1484 web_gesture
.type
> blink::WebInputEvent::Type::GestureTapCancel
)
1487 host_
->ForwardGestureEvent(web_gesture
);
1490 void RenderWidgetHostViewAura::ProcessDisambiguationMouse(
1491 ui::MouseEvent
* event
) {
1492 blink::WebMouseEvent web_mouse
= content::MakeWebMouseEvent(*event
);
1493 host_
->ForwardMouseEvent(web_mouse
);
1496 bool RenderWidgetHostViewAura::LockMouse() {
1497 aura::Window
* root_window
= window_
->GetRootWindow();
1504 mouse_locked_
= true;
1505 #if !defined(OS_WIN)
1506 window_
->SetCapture();
1508 UpdateMouseLockRegion();
1510 aura::client::CursorClient
* cursor_client
=
1511 aura::client::GetCursorClient(root_window
);
1512 if (cursor_client
) {
1513 cursor_client
->HideCursor();
1514 cursor_client
->LockCursor();
1517 if (ShouldMoveToCenter()) {
1518 synthetic_move_sent_
= true;
1519 window_
->MoveCursorTo(gfx::Rect(window_
->bounds().size()).CenterPoint());
1521 tooltip_disabler_
.reset(new aura::client::ScopedTooltipDisabler(root_window
));
1525 void RenderWidgetHostViewAura::UnlockMouse() {
1526 tooltip_disabler_
.reset();
1528 aura::Window
* root_window
= window_
->GetRootWindow();
1529 if (!mouse_locked_
|| !root_window
)
1532 mouse_locked_
= false;
1534 #if !defined(OS_WIN)
1535 window_
->ReleaseCapture();
1539 window_
->MoveCursorTo(unlocked_mouse_position_
);
1540 aura::client::CursorClient
* cursor_client
=
1541 aura::client::GetCursorClient(root_window
);
1542 if (cursor_client
) {
1543 cursor_client
->UnlockCursor();
1544 cursor_client
->ShowCursor();
1547 host_
->LostMouseLock();
1550 ////////////////////////////////////////////////////////////////////////////////
1551 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
1552 void RenderWidgetHostViewAura::SetCompositionText(
1553 const ui::CompositionText
& composition
) {
1557 // TODO(suzhe): convert both renderer_host and renderer to use
1558 // ui::CompositionText.
1559 std::vector
<blink::WebCompositionUnderline
> underlines
;
1560 underlines
.reserve(composition
.underlines
.size());
1561 for (std::vector
<ui::CompositionUnderline
>::const_iterator it
=
1562 composition
.underlines
.begin();
1563 it
!= composition
.underlines
.end(); ++it
) {
1564 underlines
.push_back(
1565 blink::WebCompositionUnderline(static_cast<unsigned>(it
->start_offset
),
1566 static_cast<unsigned>(it
->end_offset
),
1569 it
->background_color
));
1572 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
1573 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
1574 host_
->ImeSetComposition(composition
.text
, underlines
,
1575 composition
.selection
.end(),
1576 composition
.selection
.end());
1578 has_composition_text_
= !composition
.text
.empty();
1581 void RenderWidgetHostViewAura::ConfirmCompositionText() {
1582 if (host_
&& has_composition_text_
) {
1583 host_
->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
1586 has_composition_text_
= false;
1589 void RenderWidgetHostViewAura::ClearCompositionText() {
1590 if (host_
&& has_composition_text_
)
1591 host_
->ImeCancelComposition();
1592 has_composition_text_
= false;
1595 void RenderWidgetHostViewAura::InsertText(const base::string16
& text
) {
1596 DCHECK(text_input_type_
!= ui::TEXT_INPUT_TYPE_NONE
);
1598 host_
->ImeConfirmComposition(text
, gfx::Range::InvalidRange(), false);
1599 has_composition_text_
= false;
1602 void RenderWidgetHostViewAura::InsertChar(base::char16 ch
, int flags
) {
1603 if (popup_child_host_view_
&& popup_child_host_view_
->NeedsInputGrab()) {
1604 popup_child_host_view_
->InsertChar(ch
, flags
);
1608 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1609 if (host_
&& (accept_return_character_
|| ch
!= ui::VKEY_RETURN
)) {
1610 double now
= ui::EventTimeForNow().InSecondsF();
1611 // Send a blink::WebInputEvent::Char event to |host_|.
1612 NativeWebKeyboardEvent
webkit_event(ui::ET_KEY_PRESSED
,
1617 ForwardKeyboardEvent(webkit_event
);
1621 ui::TextInputType
RenderWidgetHostViewAura::GetTextInputType() const {
1622 return text_input_type_
;
1625 ui::TextInputMode
RenderWidgetHostViewAura::GetTextInputMode() const {
1626 return text_input_mode_
;
1629 int RenderWidgetHostViewAura::GetTextInputFlags() const {
1630 return text_input_flags_
;
1633 bool RenderWidgetHostViewAura::CanComposeInline() const {
1634 return can_compose_inline_
;
1637 gfx::Rect
RenderWidgetHostViewAura::ConvertRectToScreen(
1638 const gfx::Rect
& rect
) const {
1639 gfx::Point origin
= rect
.origin();
1640 gfx::Point end
= gfx::Point(rect
.right(), rect
.bottom());
1642 aura::Window
* root_window
= window_
->GetRootWindow();
1645 aura::client::ScreenPositionClient
* screen_position_client
=
1646 aura::client::GetScreenPositionClient(root_window
);
1647 if (!screen_position_client
)
1649 screen_position_client
->ConvertPointToScreen(window_
, &origin
);
1650 screen_position_client
->ConvertPointToScreen(window_
, &end
);
1651 return gfx::Rect(origin
.x(),
1653 end
.x() - origin
.x(),
1654 end
.y() - origin
.y());
1657 gfx::Rect
RenderWidgetHostViewAura::ConvertRectFromScreen(
1658 const gfx::Rect
& rect
) const {
1659 gfx::Point origin
= rect
.origin();
1660 gfx::Point end
= gfx::Point(rect
.right(), rect
.bottom());
1662 aura::Window
* root_window
= window_
->GetRootWindow();
1664 aura::client::ScreenPositionClient
* screen_position_client
=
1665 aura::client::GetScreenPositionClient(root_window
);
1666 screen_position_client
->ConvertPointFromScreen(window_
, &origin
);
1667 screen_position_client
->ConvertPointFromScreen(window_
, &end
);
1668 return gfx::Rect(origin
.x(),
1670 end
.x() - origin
.x(),
1671 end
.y() - origin
.y());
1677 gfx::Rect
RenderWidgetHostViewAura::GetCaretBounds() const {
1679 ui::RectBetweenSelectionBounds(selection_anchor_
, selection_focus_
);
1680 return ConvertRectToScreen(rect
);
1683 bool RenderWidgetHostViewAura::GetCompositionCharacterBounds(
1685 gfx::Rect
* rect
) const {
1687 if (index
>= composition_character_bounds_
.size())
1689 *rect
= ConvertRectToScreen(composition_character_bounds_
[index
]);
1693 bool RenderWidgetHostViewAura::HasCompositionText() const {
1694 return has_composition_text_
;
1697 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range
* range
) const {
1698 range
->set_start(selection_text_offset_
);
1699 range
->set_end(selection_text_offset_
+ selection_text_
.length());
1703 bool RenderWidgetHostViewAura::GetCompositionTextRange(
1704 gfx::Range
* range
) const {
1705 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1710 bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range
* range
) const {
1711 range
->set_start(selection_range_
.start());
1712 range
->set_end(selection_range_
.end());
1716 bool RenderWidgetHostViewAura::SetSelectionRange(const gfx::Range
& range
) {
1717 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1722 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range
& range
) {
1723 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1728 bool RenderWidgetHostViewAura::GetTextFromRange(
1729 const gfx::Range
& range
,
1730 base::string16
* text
) const {
1731 gfx::Range
selection_text_range(selection_text_offset_
,
1732 selection_text_offset_
+ selection_text_
.length());
1734 if (!selection_text_range
.Contains(range
)) {
1738 if (selection_text_range
.EqualsIgnoringDirection(range
)) {
1739 // Avoid calling substr whose performance is low.
1740 *text
= selection_text_
;
1742 *text
= selection_text_
.substr(
1743 range
.GetMin() - selection_text_offset_
,
1749 void RenderWidgetHostViewAura::OnInputMethodChanged() {
1753 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
1757 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
1758 base::i18n::TextDirection direction
) {
1761 host_
->UpdateTextDirection(
1762 direction
== base::i18n::RIGHT_TO_LEFT
?
1763 blink::WebTextDirectionRightToLeft
:
1764 blink::WebTextDirectionLeftToRight
);
1765 host_
->NotifyTextDirection();
1769 void RenderWidgetHostViewAura::ExtendSelectionAndDelete(
1770 size_t before
, size_t after
) {
1771 RenderFrameHostImpl
* rfh
= GetFocusedFrame();
1773 rfh
->ExtendSelectionAndDelete(before
, after
);
1776 void RenderWidgetHostViewAura::EnsureCaretInRect(const gfx::Rect
& rect
) {
1777 gfx::Rect
intersected_rect(
1778 gfx::IntersectRects(rect
, window_
->GetBoundsInScreen()));
1780 if (intersected_rect
.IsEmpty())
1783 host_
->ScrollFocusedEditableNodeIntoRect(
1784 ConvertRectFromScreen(intersected_rect
));
1787 bool RenderWidgetHostViewAura::IsEditCommandEnabled(int command_id
) {
1791 void RenderWidgetHostViewAura::SetEditCommandForNextKeyEvent(int command_id
) {
1794 ////////////////////////////////////////////////////////////////////////////////
1795 // RenderWidgetHostViewAura, gfx::DisplayObserver implementation:
1797 void RenderWidgetHostViewAura::OnDisplayAdded(
1798 const gfx::Display
& new_display
) {
1801 void RenderWidgetHostViewAura::OnDisplayRemoved(
1802 const gfx::Display
& old_display
) {
1805 void RenderWidgetHostViewAura::OnDisplayMetricsChanged(
1806 const gfx::Display
& display
, uint32_t metrics
) {
1807 // The screen info should be updated regardless of the metric change.
1808 gfx::Screen
* screen
= gfx::Screen::GetScreenFor(window_
);
1809 if (display
.id() == screen
->GetDisplayNearestWindow(window_
).id()) {
1810 UpdateScreenInfo(window_
);
1811 current_cursor_
.SetDisplayInfo(display
);
1812 UpdateCursorIfOverSelf();
1816 ////////////////////////////////////////////////////////////////////////////////
1817 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
1819 gfx::Size
RenderWidgetHostViewAura::GetMinimumSize() const {
1823 gfx::Size
RenderWidgetHostViewAura::GetMaximumSize() const {
1827 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect
& old_bounds
,
1828 const gfx::Rect
& new_bounds
) {
1829 base::AutoReset
<bool> in_bounds_changed(&in_bounds_changed_
, true);
1830 // We care about this whenever RenderWidgetHostViewAura is not owned by a
1831 // WebContentsViewAura since changes to the Window's bounds need to be
1832 // messaged to the renderer. WebContentsViewAura invokes SetSize() or
1833 // SetBounds() itself. No matter how we got here, any redundant calls are
1835 SetSize(new_bounds
.size());
1837 if (GetInputMethod())
1838 GetInputMethod()->OnCaretBoundsChanged(this);
1841 gfx::NativeCursor
RenderWidgetHostViewAura::GetCursor(const gfx::Point
& point
) {
1843 return ui::kCursorNone
;
1844 return current_cursor_
.GetNativeCursor();
1847 int RenderWidgetHostViewAura::GetNonClientComponent(
1848 const gfx::Point
& point
) const {
1852 bool RenderWidgetHostViewAura::ShouldDescendIntoChildForEventHandling(
1853 aura::Window
* child
,
1854 const gfx::Point
& location
) {
1858 bool RenderWidgetHostViewAura::CanFocus() {
1859 return popup_type_
== blink::WebPopupTypeNone
;
1862 void RenderWidgetHostViewAura::OnCaptureLost() {
1863 host_
->LostCapture();
1864 if (touch_editing_client_
)
1865 touch_editing_client_
->EndTouchEditing(false);
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");
1948 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
1951 if (popup_child_host_view_
&& popup_child_host_view_
->NeedsInputGrab()) {
1952 popup_child_host_view_
->OnKeyEvent(event
);
1953 if (event
->handled())
1957 // We need to handle the Escape key for Pepper Flash.
1958 if (is_fullscreen_
&& event
->key_code() == ui::VKEY_ESCAPE
) {
1959 // Focus the window we were created from.
1960 if (host_tracker_
.get() && !host_tracker_
->windows().empty()) {
1961 aura::Window
* host
= *(host_tracker_
->windows().begin());
1962 aura::client::FocusClient
* client
= aura::client::GetFocusClient(host
);
1964 // Calling host->Focus() may delete |this|. We create a local observer
1965 // for that. In that case we exit without further access to any members.
1966 aura::WindowTracker tracker
;
1967 aura::Window
* window
= window_
;
1968 tracker
.Add(window
);
1970 if (!tracker
.Contains(window
)) {
1971 event
->SetHandled();
1978 if (event
->key_code() == ui::VKEY_RETURN
) {
1979 // Do not forward return key release events if no press event was handled.
1980 if (event
->type() == ui::ET_KEY_RELEASED
&& !accept_return_character_
)
1982 // Accept return key character events between press and release events.
1983 accept_return_character_
= event
->type() == ui::ET_KEY_PRESSED
;
1986 // We don't have to communicate with an input method here.
1987 NativeWebKeyboardEvent
webkit_event(*event
);
1988 ForwardKeyboardEvent(webkit_event
);
1990 event
->SetHandled();
1993 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent
* event
) {
1994 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent");
1996 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
1999 if (mouse_locked_
) {
2000 aura::client::CursorClient
* cursor_client
=
2001 aura::client::GetCursorClient(window_
->GetRootWindow());
2002 DCHECK(!cursor_client
|| !cursor_client
->IsCursorVisible());
2004 if (event
->type() == ui::ET_MOUSEWHEEL
) {
2005 blink::WebMouseWheelEvent mouse_wheel_event
=
2006 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent
&>(*event
));
2007 if (mouse_wheel_event
.deltaX
!= 0 || mouse_wheel_event
.deltaY
!= 0)
2008 host_
->ForwardWheelEvent(mouse_wheel_event
);
2012 gfx::Point
center(gfx::Rect(window_
->bounds().size()).CenterPoint());
2014 // If we receive non client mouse messages while we are in the locked state
2015 // it probably means that the mouse left the borders of our window and
2016 // needs to be moved back to the center.
2017 if (event
->flags() & ui::EF_IS_NON_CLIENT
) {
2018 synthetic_move_sent_
= true;
2019 window_
->MoveCursorTo(center
);
2023 blink::WebMouseEvent mouse_event
= MakeWebMouseEvent(*event
);
2025 bool is_move_to_center_event
= (event
->type() == ui::ET_MOUSE_MOVED
||
2026 event
->type() == ui::ET_MOUSE_DRAGGED
) &&
2027 mouse_event
.x
== center
.x() && mouse_event
.y
== center
.y();
2029 // For fractional scale factors, the conversion from pixels to dip and
2030 // vice versa could result in off by 1 or 2 errors which hurts us because
2031 // we want to avoid sending the artificial move to center event to the
2032 // renderer. Sending the move to center to the renderer cause the cursor
2033 // to bounce around the center of the screen leading to the lock operation
2034 // not working correctly.
2035 // Workaround is to treat a mouse move or drag event off by at most 2 px
2036 // from the center as a move to center event.
2037 if (synthetic_move_sent_
&&
2038 IsFractionalScaleFactor(current_device_scale_factor_
)) {
2039 if (event
->type() == ui::ET_MOUSE_MOVED
||
2040 event
->type() == ui::ET_MOUSE_DRAGGED
) {
2041 if ((abs(mouse_event
.x
- center
.x()) <= 2) &&
2042 (abs(mouse_event
.y
- center
.y()) <= 2)) {
2043 is_move_to_center_event
= true;
2048 ModifyEventMovementAndCoords(&mouse_event
);
2050 bool should_not_forward
= is_move_to_center_event
&& synthetic_move_sent_
;
2051 if (should_not_forward
) {
2052 synthetic_move_sent_
= false;
2054 // Check if the mouse has reached the border and needs to be centered.
2055 if (ShouldMoveToCenter()) {
2056 synthetic_move_sent_
= true;
2057 window_
->MoveCursorTo(center
);
2059 bool is_selection_popup
= popup_child_host_view_
&&
2060 popup_child_host_view_
->NeedsInputGrab();
2061 // Forward event to renderer.
2062 if (CanRendererHandleEvent(event
, mouse_locked_
, is_selection_popup
) &&
2063 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2064 host_
->ForwardMouseEvent(mouse_event
);
2065 // Ensure that we get keyboard focus on mouse down as a plugin window
2066 // may have grabbed keyboard focus.
2067 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2074 // As the overscroll is handled during scroll events from the trackpad, the
2075 // RWHVA window is transformed by the overscroll controller. This transform
2076 // triggers a synthetic mouse-move event to be generated (by the aura
2077 // RootWindow). But this event interferes with the overscroll gesture. So,
2078 // ignore such synthetic mouse-move events if an overscroll gesture is in
2080 if (overscroll_controller_
&&
2081 overscroll_controller_
->overscroll_mode() != OVERSCROLL_NONE
&&
2082 event
->flags() & ui::EF_IS_SYNTHESIZED
&&
2083 (event
->type() == ui::ET_MOUSE_ENTERED
||
2084 event
->type() == ui::ET_MOUSE_EXITED
||
2085 event
->type() == ui::ET_MOUSE_MOVED
)) {
2086 event
->StopPropagation();
2090 if (event
->type() == ui::ET_MOUSEWHEEL
) {
2092 // We get mouse wheel/scroll messages even if we are not in the foreground.
2093 // So here we check if we have any owned popup windows in the foreground and
2095 aura::WindowTreeHost
* host
= window_
->GetHost();
2097 HWND parent
= host
->GetAcceleratedWidget();
2098 HWND toplevel_hwnd
= ::GetAncestor(parent
, GA_ROOT
);
2099 EnumThreadWindows(GetCurrentThreadId(),
2101 reinterpret_cast<LPARAM
>(toplevel_hwnd
));
2104 // The Disambiguation popup does not parent itself from this window, so we
2105 // manually dismiss it.
2106 HideDisambiguationPopup();
2108 blink::WebMouseWheelEvent mouse_wheel_event
=
2109 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent
&>(*event
));
2110 if (mouse_wheel_event
.deltaX
!= 0 || mouse_wheel_event
.deltaY
!= 0)
2111 host_
->ForwardWheelEvent(mouse_wheel_event
);
2113 bool is_selection_popup
= popup_child_host_view_
&&
2114 popup_child_host_view_
->NeedsInputGrab();
2115 if (CanRendererHandleEvent(event
, mouse_locked_
, is_selection_popup
) &&
2116 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2117 // Confirm existing composition text on mouse press, to make sure
2118 // the input caret won't be moved with an ongoing composition text.
2119 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2120 FinishImeCompositionSession();
2122 blink::WebMouseEvent mouse_event
= MakeWebMouseEvent(*event
);
2123 ModifyEventMovementAndCoords(&mouse_event
);
2124 host_
->ForwardMouseEvent(mouse_event
);
2125 // Ensure that we get keyboard focus on mouse down as a plugin window may
2126 // have grabbed keyboard focus.
2127 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2132 switch (event
->type()) {
2133 case ui::ET_MOUSE_PRESSED
:
2134 window_
->SetCapture();
2136 case ui::ET_MOUSE_RELEASED
:
2137 if (!NeedsMouseCapture())
2138 window_
->ReleaseCapture();
2144 // Needed to propagate mouse event to |window_->parent()->delegate()|, but
2145 // note that it might be something other than a WebContentsViewAura instance.
2146 // TODO(pkotwicz): Find a better way of doing this.
2147 // In fullscreen mode which is typically used by flash, don't forward
2148 // the mouse events to the parent. The renderer and the plugin process
2149 // handle these events.
2150 if (!is_fullscreen_
&& window_
->parent() && window_
->parent()->delegate() &&
2151 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2152 event
->ConvertLocationToTarget(window_
, window_
->parent());
2153 window_
->parent()->delegate()->OnMouseEvent(event
);
2156 if (!IsXButtonUpEvent(event
))
2157 event
->SetHandled();
2160 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent
* event
) {
2161 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent");
2162 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
2165 if (event
->type() == ui::ET_SCROLL
) {
2166 #if !defined(OS_WIN)
2168 // Investigate if this is true for Windows 8 Metro ASH as well.
2169 if (event
->finger_count() != 2)
2172 blink::WebGestureEvent gesture_event
=
2173 MakeWebGestureEventFlingCancel();
2174 host_
->ForwardGestureEvent(gesture_event
);
2175 blink::WebMouseWheelEvent mouse_wheel_event
=
2176 MakeWebMouseWheelEvent(*event
);
2177 host_
->ForwardWheelEvent(mouse_wheel_event
);
2178 RecordAction(base::UserMetricsAction("TrackpadScroll"));
2179 } else if (event
->type() == ui::ET_SCROLL_FLING_START
||
2180 event
->type() == ui::ET_SCROLL_FLING_CANCEL
) {
2181 blink::WebGestureEvent gesture_event
= MakeWebGestureEvent(*event
);
2182 host_
->ForwardGestureEvent(gesture_event
);
2183 if (event
->type() == ui::ET_SCROLL_FLING_START
)
2184 RecordAction(base::UserMetricsAction("TrackpadScrollFling"));
2187 event
->SetHandled();
2190 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent
* event
) {
2191 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent");
2192 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
2195 // Update the touch event first.
2196 if (!pointer_state_
.OnTouch(*event
)) {
2197 event
->StopPropagation();
2201 blink::WebTouchEvent touch_event
= ui::CreateWebTouchEventFromMotionEvent(
2202 pointer_state_
, event
->may_cause_scrolling());
2203 pointer_state_
.CleanupRemovedTouchPoints(*event
);
2205 // It is important to always mark events as being handled asynchronously when
2206 // they are forwarded. This ensures that the current event does not get
2207 // processed by the gesture recognizer before events currently awaiting
2208 // dispatch in the touch queue.
2209 event
->DisableSynchronousHandling();
2211 // Set unchanged touch point to StateStationary for touchmove and
2212 // touchcancel to make sure only send one ack per WebTouchEvent.
2213 MarkUnchangedTouchPointsAsStationary(&touch_event
, event
->touch_id());
2214 host_
->ForwardTouchEventWithLatencyInfo(touch_event
, *event
->latency());
2217 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent
* event
) {
2218 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent");
2219 if ((event
->type() == ui::ET_GESTURE_PINCH_BEGIN
||
2220 event
->type() == ui::ET_GESTURE_PINCH_UPDATE
||
2221 event
->type() == ui::ET_GESTURE_PINCH_END
) && !pinch_zoom_enabled_
) {
2222 event
->SetHandled();
2226 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
2229 // Confirm existing composition text on TAP gesture, to make sure the input
2230 // caret won't be moved with an ongoing composition text.
2231 if (event
->type() == ui::ET_GESTURE_TAP
)
2232 FinishImeCompositionSession();
2234 blink::WebGestureEvent gesture
= MakeWebGestureEvent(*event
);
2235 if (event
->type() == ui::ET_GESTURE_TAP_DOWN
) {
2236 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an
2237 // event to stop any in-progress flings.
2238 blink::WebGestureEvent fling_cancel
= gesture
;
2239 fling_cancel
.type
= blink::WebInputEvent::GestureFlingCancel
;
2240 fling_cancel
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
2241 host_
->ForwardGestureEvent(fling_cancel
);
2244 if (gesture
.type
!= blink::WebInputEvent::Undefined
) {
2245 host_
->ForwardGestureEventWithLatencyInfo(gesture
, *event
->latency());
2247 if (event
->type() == ui::ET_GESTURE_SCROLL_BEGIN
||
2248 event
->type() == ui::ET_GESTURE_SCROLL_UPDATE
||
2249 event
->type() == ui::ET_GESTURE_SCROLL_END
) {
2250 RecordAction(base::UserMetricsAction("TouchscreenScroll"));
2251 } else if (event
->type() == ui::ET_SCROLL_FLING_START
) {
2252 RecordAction(base::UserMetricsAction("TouchscreenScrollFling"));
2256 // If a gesture is not processed by the webpage, then WebKit processes it
2257 // (e.g. generates synthetic mouse events).
2258 event
->SetHandled();
2261 ////////////////////////////////////////////////////////////////////////////////
2262 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation:
2264 bool RenderWidgetHostViewAura::ShouldActivate() const {
2265 aura::WindowTreeHost
* host
= window_
->GetHost();
2268 const ui::Event
* event
= host
->dispatcher()->current_event();
2271 return is_fullscreen_
;
2274 ////////////////////////////////////////////////////////////////////////////////
2275 // RenderWidgetHostViewAura, aura::client::CursorClientObserver implementation:
2277 void RenderWidgetHostViewAura::OnCursorVisibilityChanged(bool is_visible
) {
2278 NotifyRendererOfCursorVisibilityState(is_visible
);
2281 ////////////////////////////////////////////////////////////////////////////////
2282 // RenderWidgetHostViewAura, aura::client::FocusChangeObserver implementation:
2284 void RenderWidgetHostViewAura::OnWindowFocused(aura::Window
* gained_focus
,
2285 aura::Window
* lost_focus
) {
2286 DCHECK(window_
== gained_focus
|| window_
== lost_focus
);
2287 if (window_
== gained_focus
) {
2288 // We need to honor input bypass if the associated tab is does not want
2289 // input. This gives the current focused window a chance to be the text
2290 // input client and handle events.
2291 if (host_
->ignore_input_events())
2295 host_
->SetActive(true);
2297 ui::InputMethod
* input_method
= GetInputMethod();
2299 // Ask the system-wide IME to send all TextInputClient messages to |this|
2301 input_method
->SetFocusedTextInputClient(this);
2303 // Often the application can set focus to the view in response to a key
2304 // down. However the following char event shouldn't be sent to the web
2306 host_
->SuppressNextCharEvents();
2309 BrowserAccessibilityManager
* manager
=
2310 host_
->GetRootBrowserAccessibilityManager();
2312 manager
->OnWindowFocused();
2313 } else if (window_
== lost_focus
) {
2314 host_
->SetActive(false);
2317 DetachFromInputMethod();
2319 if (touch_editing_client_
)
2320 touch_editing_client_
->EndTouchEditing(false);
2322 if (overscroll_controller_
)
2323 overscroll_controller_
->Cancel();
2325 BrowserAccessibilityManager
* manager
=
2326 host_
->GetRootBrowserAccessibilityManager();
2328 manager
->OnWindowBlurred();
2330 // If we lose the focus while fullscreen, close the window; Pepper Flash
2331 // won't do it for us (unlike NPAPI Flash). However, we do not close the
2332 // window if we lose the focus to a window on another display.
2333 gfx::Screen
* screen
= gfx::Screen::GetScreenFor(window_
);
2334 bool focusing_other_display
=
2335 gained_focus
&& screen
->GetNumDisplays() > 1 &&
2336 (screen
->GetDisplayNearestWindow(window_
).id() !=
2337 screen
->GetDisplayNearestWindow(gained_focus
).id());
2338 if (is_fullscreen_
&& !in_shutdown_
&& !focusing_other_display
) {
2340 // On Windows, if we are switching to a non Aura Window on a different
2341 // screen we should not close the fullscreen window.
2342 if (!gained_focus
) {
2344 ::GetCursorPos(&point
);
2345 if (screen
->GetDisplayNearestWindow(window_
).id() !=
2346 screen
->GetDisplayNearestPoint(gfx::Point(point
)).id())
2354 // Close the child popup window if we lose focus (e.g. due to a JS alert or
2355 // system modal dialog). This is particularly important if
2356 // |popup_child_host_view_| has mouse capture.
2357 if (popup_child_host_view_
)
2358 popup_child_host_view_
->Shutdown();
2362 ////////////////////////////////////////////////////////////////////////////////
2363 // RenderWidgetHostViewAura, aura::WindowTreeHostObserver implementation:
2365 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost
* host
,
2366 const gfx::Point
& new_origin
) {
2367 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved",
2368 "new_origin", new_origin
.ToString());
2370 UpdateScreenInfo(window_
);
2373 ////////////////////////////////////////////////////////////////////////////////
2374 // RenderWidgetHostViewAura, private:
2376 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
2377 if (touch_editing_client_
)
2378 touch_editing_client_
->OnViewDestroyed();
2380 delegated_frame_host_
.reset();
2381 window_observer_
.reset();
2382 if (window_
->GetHost())
2383 window_
->GetHost()->RemoveObserver(this);
2385 if (popup_parent_host_view_
) {
2386 DCHECK(popup_parent_host_view_
->popup_child_host_view_
== NULL
||
2387 popup_parent_host_view_
->popup_child_host_view_
== this);
2388 popup_parent_host_view_
->popup_child_host_view_
= NULL
;
2390 if (popup_child_host_view_
) {
2391 DCHECK(popup_child_host_view_
->popup_parent_host_view_
== NULL
||
2392 popup_child_host_view_
->popup_parent_host_view_
== this);
2393 popup_child_host_view_
->popup_parent_host_view_
= NULL
;
2395 event_filter_for_popup_exit_
.reset();
2396 aura::client::SetTooltipText(window_
, NULL
);
2397 gfx::Screen::GetScreenFor(window_
)->RemoveObserver(this);
2399 // This call is usually no-op since |this| object is already removed from the
2400 // Aura root window and we don't have a way to get an input method object
2401 // associated with the window, but just in case.
2402 DetachFromInputMethod();
2405 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2406 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2408 DCHECK(!legacy_render_widget_host_HWND_
);
2412 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
2413 const gfx::Point screen_point
=
2414 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint();
2415 aura::Window
* root_window
= window_
->GetRootWindow();
2419 gfx::Point root_window_point
= screen_point
;
2420 aura::client::ScreenPositionClient
* screen_position_client
=
2421 aura::client::GetScreenPositionClient(root_window
);
2422 if (screen_position_client
) {
2423 screen_position_client
->ConvertPointFromScreen(
2424 root_window
, &root_window_point
);
2427 if (root_window
->GetEventHandlerForPoint(root_window_point
) != window_
)
2430 gfx::NativeCursor cursor
= current_cursor_
.GetNativeCursor();
2431 // Do not show loading cursor when the cursor is currently hidden.
2432 if (is_loading_
&& cursor
!= ui::kCursorNone
)
2433 cursor
= ui::kCursorPointer
;
2435 aura::client::CursorClient
* cursor_client
=
2436 aura::client::GetCursorClient(root_window
);
2437 if (cursor_client
) {
2438 cursor_client
->SetCursor(cursor
);
2442 ui::InputMethod
* RenderWidgetHostViewAura::GetInputMethod() const {
2443 aura::Window
* root_window
= window_
->GetRootWindow();
2446 return root_window
->GetHost()->GetInputMethod();
2449 void RenderWidgetHostViewAura::Shutdown() {
2450 if (!in_shutdown_
) {
2451 in_shutdown_
= true;
2456 bool RenderWidgetHostViewAura::NeedsInputGrab() {
2457 return popup_type_
== blink::WebPopupTypePage
;
2460 bool RenderWidgetHostViewAura::NeedsMouseCapture() {
2461 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2462 return NeedsInputGrab();
2467 void RenderWidgetHostViewAura::FinishImeCompositionSession() {
2468 if (!has_composition_text_
)
2471 host_
->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
2474 ImeCancelComposition();
2477 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords(
2478 blink::WebMouseEvent
* event
) {
2479 // If the mouse has just entered, we must report zero movementX/Y. Hence we
2480 // reset any global_mouse_position set previously.
2481 if (event
->type
== blink::WebInputEvent::MouseEnter
||
2482 event
->type
== blink::WebInputEvent::MouseLeave
)
2483 global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2485 // Movement is computed by taking the difference of the new cursor position
2486 // and the previous. Under mouse lock the cursor will be warped back to the
2487 // center so that we are not limited by clipping boundaries.
2488 // We do not measure movement as the delta from cursor to center because
2489 // we may receive more mouse movement events before our warp has taken
2491 event
->movementX
= event
->globalX
- global_mouse_position_
.x();
2492 event
->movementY
= event
->globalY
- global_mouse_position_
.y();
2494 global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2496 // Under mouse lock, coordinates of mouse are locked to what they were when
2497 // mouse lock was entered.
2498 if (mouse_locked_
) {
2499 event
->x
= unlocked_mouse_position_
.x();
2500 event
->y
= unlocked_mouse_position_
.y();
2501 event
->windowX
= unlocked_mouse_position_
.x();
2502 event
->windowY
= unlocked_mouse_position_
.y();
2503 event
->globalX
= unlocked_global_mouse_position_
.x();
2504 event
->globalY
= unlocked_global_mouse_position_
.y();
2506 unlocked_mouse_position_
.SetPoint(event
->x
, event
->y
);
2507 unlocked_global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2511 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState(
2513 if (host_
->is_hidden() ||
2514 (cursor_visibility_state_in_renderer_
== VISIBLE
&& is_visible
) ||
2515 (cursor_visibility_state_in_renderer_
== NOT_VISIBLE
&& !is_visible
))
2518 cursor_visibility_state_in_renderer_
= is_visible
? VISIBLE
: NOT_VISIBLE
;
2519 host_
->SendCursorVisibilityState(is_visible
);
2522 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled
) {
2524 overscroll_controller_
.reset();
2525 else if (!overscroll_controller_
)
2526 overscroll_controller_
.reset(new OverscrollController());
2529 void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() {
2530 // The top left corner of our view in window coordinates might not land on a
2531 // device pixel boundary if we have a non-integer device scale. In that case,
2532 // to avoid the web contents area looking blurry we translate the web contents
2533 // in the +x, +y direction to land on the nearest pixel boundary. This may
2534 // cause the bottom and right edges to be clipped slightly, but that's ok.
2535 aura::Window
* snapped
= NULL
;
2536 // On desktop, use the root window. On alternative environment (ash),
2537 // use the toplevel window which must be already snapped.
2538 if (gfx::Screen::GetScreenFor(window_
) !=
2539 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
)) {
2540 snapped
= window_
->GetRootWindow();
2542 snapped
= window_
->GetToplevelWindow();
2544 if (snapped
&& snapped
!= window_
)
2545 ui::SnapLayerToPhysicalPixelBoundary(snapped
->layer(), window_
->layer());
2547 has_snapped_to_boundary_
= true;
2550 void RenderWidgetHostViewAura::OnShowContextMenu() {
2552 showing_context_menu_
= true;
2556 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect
& rect
) {
2557 SnapToPhysicalPixelBoundary();
2558 // Don't recursively call SetBounds if this bounds update is the result of
2559 // a Window::SetBoundsInternal call.
2560 if (!in_bounds_changed_
)
2561 window_
->SetBounds(rect
);
2562 host_
->WasResized();
2563 delegated_frame_host_
->WasResized();
2564 if (touch_editing_client_
) {
2565 touch_editing_client_
->OnSelectionOrCursorChanged(selection_anchor_
,
2569 // Create the legacy dummy window which corresponds to the bounds of the
2570 // webcontents. This will be passed as the container window for windowless
2572 // Plugins like Flash assume the container window which is returned via the
2573 // NPNVnetscapeWindow property corresponds to the bounds of the webpage.
2574 // This is not true in Aura where we have only HWND which is the main Aura
2575 // window. If we return this window to plugins like Flash then it causes the
2576 // coordinate translations done by these plugins to break.
2577 // Additonally the legacy dummy window is needed for accessibility and for
2578 // scrolling to work in legacy drivers for trackpoints/trackpads, etc.
2579 if (!legacy_window_destroyed_
&& GetNativeViewId()) {
2580 if (!legacy_render_widget_host_HWND_
) {
2581 legacy_render_widget_host_HWND_
= LegacyRenderWidgetHostHWND::Create(
2582 reinterpret_cast<HWND
>(GetNativeViewId()));
2584 if (legacy_render_widget_host_HWND_
) {
2585 legacy_render_widget_host_HWND_
->set_host(this);
2586 legacy_render_widget_host_HWND_
->SetBounds(
2587 window_
->GetBoundsInRootWindow());
2588 // There are cases where the parent window is created, made visible and
2589 // the associated RenderWidget is also visible before the
2590 // LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown
2592 if (!host_
->is_hidden())
2593 legacy_render_widget_host_HWND_
->Show();
2598 UpdateMouseLockRegion();
2602 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip(
2603 const gfx::Rect
& rect
,
2604 const gfx::Rect
& clip
) {
2605 if (!clip
.IsEmpty()) {
2606 gfx::Rect to_paint
= gfx::SubtractRects(rect
, clip
);
2607 if (!to_paint
.IsEmpty())
2608 window_
->SchedulePaintInRect(to_paint
);
2610 window_
->SchedulePaintInRect(rect
);
2614 bool RenderWidgetHostViewAura::ShouldMoveToCenter() {
2615 gfx::Rect rect
= window_
->bounds();
2616 rect
= ConvertRectToScreen(rect
);
2617 int border_x
= rect
.width() * kMouseLockBorderPercentage
/ 100;
2618 int border_y
= rect
.height() * kMouseLockBorderPercentage
/ 100;
2620 return global_mouse_position_
.x() < rect
.x() + border_x
||
2621 global_mouse_position_
.x() > rect
.right() - border_x
||
2622 global_mouse_position_
.y() < rect
.y() + border_y
||
2623 global_mouse_position_
.y() > rect
.bottom() - border_y
;
2626 void RenderWidgetHostViewAura::AddedToRootWindow() {
2627 window_
->GetHost()->AddObserver(this);
2628 UpdateScreenInfo(window_
);
2630 aura::client::CursorClient
* cursor_client
=
2631 aura::client::GetCursorClient(window_
->GetRootWindow());
2632 if (cursor_client
) {
2633 cursor_client
->AddObserver(this);
2634 NotifyRendererOfCursorVisibilityState(cursor_client
->IsCursorVisible());
2637 ui::InputMethod
* input_method
= GetInputMethod();
2639 input_method
->SetFocusedTextInputClient(this);
2643 // The parent may have changed here. Ensure that the legacy window is
2644 // reparented accordingly.
2645 if (legacy_render_widget_host_HWND_
)
2646 legacy_render_widget_host_HWND_
->UpdateParent(
2647 reinterpret_cast<HWND
>(GetNativeViewId()));
2650 delegated_frame_host_
->SetCompositor(window_
->GetHost()->compositor());
2651 if (window_
->GetHost()->compositor())
2652 begin_frame_observer_proxy_
.SetCompositor(window_
->GetHost()->compositor());
2655 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2656 aura::client::CursorClient
* cursor_client
=
2657 aura::client::GetCursorClient(window_
->GetRootWindow());
2659 cursor_client
->RemoveObserver(this);
2661 DetachFromInputMethod();
2663 window_
->GetHost()->RemoveObserver(this);
2664 delegated_frame_host_
->ResetCompositor();
2665 begin_frame_observer_proxy_
.ResetCompositor();
2668 // Update the legacy window's parent temporarily to the desktop window. It
2669 // will eventually get reparented to the right root.
2670 if (legacy_render_widget_host_HWND_
)
2671 legacy_render_widget_host_HWND_
->UpdateParent(::GetDesktopWindow());
2675 void RenderWidgetHostViewAura::DetachFromInputMethod() {
2676 ui::InputMethod
* input_method
= GetInputMethod();
2678 input_method
->DetachTextInputClient(this);
2681 void RenderWidgetHostViewAura::ForwardKeyboardEvent(
2682 const NativeWebKeyboardEvent
& event
) {
2683 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2684 ui::TextEditKeyBindingsDelegateAuraLinux
* keybinding_delegate
=
2685 ui::GetTextEditKeyBindingsDelegate();
2686 std::vector
<ui::TextEditCommandAuraLinux
> commands
;
2687 if (!event
.skip_in_browser
&&
2688 keybinding_delegate
&&
2690 keybinding_delegate
->MatchEvent(*event
.os_event
, &commands
)) {
2691 // Transform from ui/ types to content/ types.
2692 EditCommands edit_commands
;
2693 for (std::vector
<ui::TextEditCommandAuraLinux
>::const_iterator it
=
2694 commands
.begin(); it
!= commands
.end(); ++it
) {
2695 edit_commands
.push_back(EditCommand(it
->GetCommandString(),
2698 host_
->Send(new InputMsg_SetEditCommandsForNextKeyEvent(
2699 host_
->GetRoutingID(), edit_commands
));
2700 NativeWebKeyboardEvent
copy_event(event
);
2701 copy_event
.match_edit_command
= true;
2702 host_
->ForwardKeyboardEvent(copy_event
);
2707 host_
->ForwardKeyboardEvent(event
);
2710 ////////////////////////////////////////////////////////////////////////////////
2711 // DelegatedFrameHost, public:
2713 ui::Layer
* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const {
2714 return window_
->layer();
2717 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const {
2718 return !host_
->is_hidden();
2721 gfx::Size
RenderWidgetHostViewAura::DelegatedFrameHostDesiredSizeInDIP() const {
2722 return window_
->bounds().size();
2725 bool RenderWidgetHostViewAura::DelegatedFrameCanCreateResizeLock() const {
2726 #if !defined(OS_CHROMEOS)
2727 // On Windows and Linux, holding pointer moves will not help throttling
2729 // TODO(piman): on Windows we need to block (nested message loop?) the
2730 // WM_SIZE event. On Linux we need to throttle at the WM level using
2731 // _NET_WM_SYNC_REQUEST.
2734 if (host_
->auto_resize_enabled())
2740 scoped_ptr
<ResizeLock
>
2741 RenderWidgetHostViewAura::DelegatedFrameHostCreateResizeLock(
2742 bool defer_compositor_lock
) {
2743 gfx::Size desired_size
= window_
->bounds().size();
2744 return scoped_ptr
<ResizeLock
>(new CompositorResizeLock(
2747 defer_compositor_lock
,
2748 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs
)));
2751 void RenderWidgetHostViewAura::DelegatedFrameHostResizeLockWasReleased() {
2752 host_
->WasResized();
2755 void RenderWidgetHostViewAura::DelegatedFrameHostSendCompositorSwapAck(
2756 int output_surface_id
,
2757 const cc::CompositorFrameAck
& ack
) {
2758 host_
->Send(new ViewMsg_SwapCompositorFrameAck(host_
->GetRoutingID(),
2759 output_surface_id
, ack
));
2762 void RenderWidgetHostViewAura::DelegatedFrameHostSendReclaimCompositorResources(
2763 int output_surface_id
,
2764 const cc::CompositorFrameAck
& ack
) {
2765 host_
->Send(new ViewMsg_ReclaimCompositorResources(host_
->GetRoutingID(),
2766 output_surface_id
, ack
));
2769 void RenderWidgetHostViewAura::DelegatedFrameHostOnLostCompositorResources() {
2770 host_
->ScheduleComposite();
2773 void RenderWidgetHostViewAura::DelegatedFrameHostUpdateVSyncParameters(
2774 const base::TimeTicks
& timebase
,
2775 const base::TimeDelta
& interval
) {
2776 host_
->UpdateVSyncParameters(timebase
, interval
);
2779 void RenderWidgetHostViewAura::OnDidNavigateMainFrameToNewPage() {
2780 ui::GestureRecognizer::Get()->CancelActiveTouches(window_
);
2783 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() {
2784 return delegated_frame_host_
->GetSurfaceIdNamespace();
2787 ////////////////////////////////////////////////////////////////////////////////
2788 // RenderWidgetHostViewBase, public:
2791 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo
* results
) {
2792 GetScreenInfoForWindow(results
, NULL
);
2795 } // namespace content