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 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames
,
493 OnSetNeedsBeginFrames
)
494 IPC_MESSAGE_UNHANDLED(handled
= false)
495 IPC_END_MESSAGE_MAP()
499 void RenderWidgetHostViewAura::InitAsChild(
500 gfx::NativeView parent_view
) {
501 window_
->SetType(ui::wm::WINDOW_TYPE_CONTROL
);
502 window_
->Init(ui::LAYER_SOLID_COLOR
);
503 window_
->SetName("RenderWidgetHostViewAura");
504 window_
->layer()->SetColor(background_color_
);
507 void RenderWidgetHostViewAura::InitAsPopup(
508 RenderWidgetHostView
* parent_host_view
,
509 const gfx::Rect
& bounds_in_screen
) {
510 popup_parent_host_view_
=
511 static_cast<RenderWidgetHostViewAura
*>(parent_host_view
);
513 // TransientWindowClient may be NULL during tests.
514 aura::client::TransientWindowClient
* transient_window_client
=
515 aura::client::GetTransientWindowClient();
516 RenderWidgetHostViewAura
* old_child
=
517 popup_parent_host_view_
->popup_child_host_view_
;
519 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or
520 // similar mechanism to ensure a second popup doesn't cause the first one
521 // to never get a chance to filter events. See crbug.com/160589.
522 DCHECK(old_child
->popup_parent_host_view_
== popup_parent_host_view_
);
523 if (transient_window_client
) {
524 transient_window_client
->RemoveTransientChild(
525 popup_parent_host_view_
->window_
, old_child
->window_
);
527 old_child
->popup_parent_host_view_
= NULL
;
529 popup_parent_host_view_
->popup_child_host_view_
= this;
530 window_
->SetType(ui::wm::WINDOW_TYPE_MENU
);
531 window_
->Init(ui::LAYER_SOLID_COLOR
);
532 window_
->SetName("RenderWidgetHostViewAura");
533 window_
->layer()->SetColor(background_color_
);
535 // Setting the transient child allows for the popup to get mouse events when
536 // in a system modal dialog. Do this before calling ParentWindowWithContext
537 // below so that the transient parent is visible to WindowTreeClient.
538 // This fixes crbug.com/328593.
539 if (transient_window_client
) {
540 transient_window_client
->AddTransientChild(
541 popup_parent_host_view_
->window_
, window_
);
544 aura::Window
* root
= popup_parent_host_view_
->window_
->GetRootWindow();
545 aura::client::ParentWindowWithContext(window_
, root
, bounds_in_screen
);
547 SetBounds(bounds_in_screen
);
549 if (NeedsMouseCapture())
550 window_
->SetCapture();
552 event_filter_for_popup_exit_
.reset(new EventFilterForPopupExit(this));
555 void RenderWidgetHostViewAura::InitAsFullscreen(
556 RenderWidgetHostView
* reference_host_view
) {
557 is_fullscreen_
= true;
558 window_
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
559 window_
->Init(ui::LAYER_SOLID_COLOR
);
560 window_
->SetName("RenderWidgetHostViewAura");
561 window_
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
562 window_
->layer()->SetColor(background_color_
);
564 aura::Window
* parent
= NULL
;
566 if (reference_host_view
) {
567 aura::Window
* reference_window
=
568 static_cast<RenderWidgetHostViewAura
*>(reference_host_view
)->window_
;
569 if (reference_window
) {
570 host_tracker_
.reset(new aura::WindowTracker
);
571 host_tracker_
->Add(reference_window
);
573 gfx::Display display
= gfx::Screen::GetScreenFor(window_
)->
574 GetDisplayNearestWindow(reference_window
);
575 parent
= reference_window
->GetRootWindow();
576 bounds
= display
.bounds();
578 aura::client::ParentWindowWithContext(window_
, parent
, bounds
);
583 RenderWidgetHost
* RenderWidgetHostViewAura::GetRenderWidgetHost() const {
587 void RenderWidgetHostViewAura::Show() {
591 if (!host_
->is_hidden())
594 bool has_saved_frame
= delegated_frame_host_
->HasSavedFrame();
595 ui::LatencyInfo renderer_latency_info
, browser_latency_info
;
596 if (has_saved_frame
) {
597 browser_latency_info
.AddLatencyNumber(
598 ui::TAB_SHOW_COMPONENT
, host_
->GetLatencyComponentId(), 0);
600 renderer_latency_info
.AddLatencyNumber(
601 ui::TAB_SHOW_COMPONENT
, host_
->GetLatencyComponentId(), 0);
603 host_
->WasShown(renderer_latency_info
);
605 aura::Window
* root
= window_
->GetRootWindow();
607 aura::client::CursorClient
* cursor_client
=
608 aura::client::GetCursorClient(root
);
610 NotifyRendererOfCursorVisibilityState(cursor_client
->IsCursorVisible());
613 delegated_frame_host_
->WasShown(browser_latency_info
);
616 if (legacy_render_widget_host_HWND_
) {
617 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent
618 // window before reparenting any plugins. This ensures that the plugin
619 // windows stay on top of the child Zorder in the parent and receive
620 // mouse events, etc.
621 legacy_render_widget_host_HWND_
->UpdateParent(
622 GetNativeView()->GetHost()->GetAcceleratedWidget());
623 legacy_render_widget_host_HWND_
->SetBounds(
624 window_
->GetBoundsInRootWindow());
626 LPARAM lparam
= reinterpret_cast<LPARAM
>(this);
627 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback
, lparam
);
629 if (legacy_render_widget_host_HWND_
)
630 legacy_render_widget_host_HWND_
->Show();
634 void RenderWidgetHostViewAura::Hide() {
637 if (host_
&& !host_
->is_hidden()) {
639 delegated_frame_host_
->WasHidden();
642 constrained_rects_
.clear();
643 aura::WindowTreeHost
* host
= window_
->GetHost();
645 HWND parent
= host
->GetAcceleratedWidget();
646 LPARAM lparam
= reinterpret_cast<LPARAM
>(this);
647 EnumChildWindows(parent
, HideWindowsCallback
, lparam
);
648 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
649 // hidden window on the same lines as Windowed plugin windows.
650 if (legacy_render_widget_host_HWND_
)
651 legacy_render_widget_host_HWND_
->UpdateParent(ui::GetHiddenWindow());
657 if (legacy_render_widget_host_HWND_
)
658 legacy_render_widget_host_HWND_
->Hide();
662 void RenderWidgetHostViewAura::SetSize(const gfx::Size
& size
) {
663 // For a SetSize operation, we don't care what coordinate system the origin
664 // of the window is in, it's only important to make sure that the origin
665 // remains constant after the operation.
666 InternalSetBounds(gfx::Rect(window_
->bounds().origin(), size
));
669 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect
& rect
) {
670 gfx::Point
relative_origin(rect
.origin());
672 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but
673 // Window::SetBounds() takes parent coordinates, so do the conversion here.
674 aura::Window
* root
= window_
->GetRootWindow();
676 aura::client::ScreenPositionClient
* screen_position_client
=
677 aura::client::GetScreenPositionClient(root
);
678 if (screen_position_client
) {
679 screen_position_client
->ConvertPointFromScreen(
680 window_
->parent(), &relative_origin
);
684 InternalSetBounds(gfx::Rect(relative_origin
, rect
.size()));
687 gfx::Vector2dF
RenderWidgetHostViewAura::GetLastScrollOffset() const {
688 return last_scroll_offset_
;
691 gfx::NativeView
RenderWidgetHostViewAura::GetNativeView() const {
695 gfx::NativeViewId
RenderWidgetHostViewAura::GetNativeViewId() const {
697 aura::WindowTreeHost
* host
= window_
->GetHost();
699 return reinterpret_cast<gfx::NativeViewId
>(host
->GetAcceleratedWidget());
701 return static_cast<gfx::NativeViewId
>(NULL
);
704 gfx::NativeViewAccessible
RenderWidgetHostViewAura::GetNativeViewAccessible() {
706 aura::WindowTreeHost
* host
= window_
->GetHost();
708 return static_cast<gfx::NativeViewAccessible
>(NULL
);
709 BrowserAccessibilityManager
* manager
=
710 host_
->GetOrCreateRootBrowserAccessibilityManager();
712 return manager
->GetRoot()->ToBrowserAccessibilityWin();
716 return static_cast<gfx::NativeViewAccessible
>(NULL
);
719 ui::TextInputClient
* RenderWidgetHostViewAura::GetTextInputClient() {
723 void RenderWidgetHostViewAura::OnSetNeedsBeginFrames(bool needs_begin_frames
) {
724 begin_frame_observer_proxy_
.SetNeedsBeginFrames(needs_begin_frames
);
727 void RenderWidgetHostViewAura::SendBeginFrame(const cc::BeginFrameArgs
& args
) {
728 delegated_frame_host_
->SetVSyncParameters(args
.frame_time
, args
.interval
);
729 host_
->Send(new ViewMsg_BeginFrame(host_
->GetRoutingID(), args
));
732 void RenderWidgetHostViewAura::SetKeyboardFocus() {
735 aura::WindowTreeHost
* host
= window_
->GetHost();
737 ::SetFocus(host
->GetAcceleratedWidget());
742 RenderFrameHostImpl
* RenderWidgetHostViewAura::GetFocusedFrame() {
743 if (!host_
->IsRenderView())
745 RenderViewHost
* rvh
= RenderViewHost::From(host_
);
746 FrameTreeNode
* focused_frame
=
747 rvh
->GetDelegate()->GetFrameTree()->GetFocusedFrame();
751 return focused_frame
->current_frame_host();
754 bool RenderWidgetHostViewAura::CanRendererHandleEvent(
755 const ui::MouseEvent
* event
,
757 bool selection_popup
) {
759 bool showing_context_menu
= showing_context_menu_
;
760 showing_context_menu_
= false;
763 if (event
->type() == ui::ET_MOUSE_CAPTURE_CHANGED
)
766 if ((mouse_locked
|| selection_popup
) &&
767 (event
->type() == ui::ET_MOUSE_EXITED
))
771 // Don't forward the mouse leave message which is received when the context
772 // menu is displayed by the page. This confuses the page and causes state
774 if (showing_context_menu
) {
775 if (event
->type() == ui::ET_MOUSE_EXITED
)
778 // Renderer cannot handle WM_XBUTTON or NC events.
779 switch (event
->native_event().message
) {
782 case WM_XBUTTONDBLCLK
:
783 case WM_NCMOUSELEAVE
:
785 case WM_NCLBUTTONDOWN
:
787 case WM_NCLBUTTONDBLCLK
:
788 case WM_NCRBUTTONDOWN
:
790 case WM_NCRBUTTONDBLCLK
:
791 case WM_NCMBUTTONDOWN
:
793 case WM_NCMBUTTONDBLCLK
:
794 case WM_NCXBUTTONDOWN
:
796 case WM_NCXBUTTONDBLCLK
:
801 #elif defined(USE_X11)
802 // Renderer only supports standard mouse buttons, so ignore programmable
804 switch (event
->type()) {
805 case ui::ET_MOUSE_PRESSED
:
806 case ui::ET_MOUSE_RELEASED
: {
807 const int kAllowedButtons
= ui::EF_LEFT_MOUSE_BUTTON
|
808 ui::EF_MIDDLE_MOUSE_BUTTON
|
809 ui::EF_RIGHT_MOUSE_BUTTON
;
810 return (event
->flags() & kAllowedButtons
) != 0;
819 void RenderWidgetHostViewAura::HandleParentBoundsChanged() {
820 SnapToPhysicalPixelBoundary();
822 if (legacy_render_widget_host_HWND_
) {
823 legacy_render_widget_host_HWND_
->SetBounds(
824 window_
->GetBoundsInRootWindow());
828 host_
->SendScreenRects();
831 void RenderWidgetHostViewAura::ParentHierarchyChanged() {
832 ancestor_window_observer_
.reset(new WindowAncestorObserver(this));
833 // Snap when we receive a hierarchy changed. http://crbug.com/388908.
834 HandleParentBoundsChanged();
837 void RenderWidgetHostViewAura::MovePluginWindows(
838 const std::vector
<WebPluginGeometry
>& plugin_window_moves
) {
840 // We need to clip the rectangle to the tab's viewport, otherwise we will draw
841 // over the browser UI.
842 if (!window_
->GetRootWindow()) {
843 DCHECK(plugin_window_moves
.empty());
846 HWND parent
= window_
->GetHost()->GetAcceleratedWidget();
847 gfx::Rect view_bounds
= window_
->GetBoundsInRootWindow();
848 std::vector
<WebPluginGeometry
> moves
= plugin_window_moves
;
850 gfx::Rect
view_port(view_bounds
.size());
852 for (size_t i
= 0; i
< moves
.size(); ++i
) {
853 gfx::Rect
clip(moves
[i
].clip_rect
);
854 gfx::Vector2d
view_port_offset(
855 moves
[i
].window_rect
.OffsetFromOrigin());
856 clip
.Offset(view_port_offset
);
857 clip
.Intersect(view_port
);
858 clip
.Offset(-view_port_offset
);
859 moves
[i
].clip_rect
= clip
;
861 moves
[i
].window_rect
.Offset(view_bounds
.OffsetFromOrigin());
863 plugin_window_moves_
[moves
[i
].window
] = moves
[i
];
865 // constrained_rects_ are relative to the root window. We want to convert
866 // them to be relative to the plugin window.
867 for (size_t j
= 0; j
< constrained_rects_
.size(); ++j
) {
868 gfx::Rect offset_cutout
= constrained_rects_
[j
];
869 offset_cutout
-= moves
[i
].window_rect
.OffsetFromOrigin();
870 moves
[i
].cutout_rects
.push_back(offset_cutout
);
874 MovePluginWindowsHelper(parent
, moves
);
876 // Make sure each plugin window (or its wrapper if it exists) has a pointer to
878 for (size_t i
= 0; i
< moves
.size(); ++i
) {
879 HWND window
= moves
[i
].window
;
880 if (GetParent(window
) != parent
) {
881 window
= GetParent(window
);
883 if (!GetProp(window
, kWidgetOwnerProperty
))
884 SetProp(window
, kWidgetOwnerProperty
, this);
886 #endif // defined(OS_WIN)
889 void RenderWidgetHostViewAura::Focus() {
890 // Make sure we have a FocusClient before attempting to Focus(). In some
891 // situations we may not yet be in a valid Window hierarchy (such as reloading
892 // after out of memory discarded the tab).
893 aura::client::FocusClient
* client
= aura::client::GetFocusClient(window_
);
898 bool RenderWidgetHostViewAura::HasFocus() const {
899 return window_
->HasFocus();
902 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const {
903 return delegated_frame_host_
->CanCopyToBitmap();
906 bool RenderWidgetHostViewAura::IsShowing() {
907 return window_
->IsVisible();
910 gfx::Rect
RenderWidgetHostViewAura::GetViewBounds() const {
911 return window_
->GetBoundsInScreen();
914 void RenderWidgetHostViewAura::SetBackgroundColor(SkColor color
) {
915 RenderWidgetHostViewBase::SetBackgroundColor(color
);
916 bool opaque
= GetBackgroundOpaque();
917 host_
->SetBackgroundOpaque(opaque
);
918 window_
->layer()->SetFillsBoundsOpaquely(opaque
);
919 window_
->layer()->SetColor(color
);
922 gfx::Size
RenderWidgetHostViewAura::GetVisibleViewportSize() const {
923 gfx::Rect
requested_rect(GetRequestedRendererSize());
924 requested_rect
.Inset(insets_
);
925 return requested_rect
.size();
928 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets
& insets
) {
929 if (insets
!= insets_
) {
935 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor
& cursor
) {
936 current_cursor_
= cursor
;
937 const gfx::Display display
= gfx::Screen::GetScreenFor(window_
)->
938 GetDisplayNearestWindow(window_
);
939 current_cursor_
.SetDisplayInfo(display
);
940 UpdateCursorIfOverSelf();
943 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading
) {
944 is_loading_
= is_loading
;
945 UpdateCursorIfOverSelf();
948 void RenderWidgetHostViewAura::TextInputStateChanged(
949 const ViewHostMsg_TextInputState_Params
& params
) {
950 if (text_input_type_
!= params
.type
||
951 text_input_mode_
!= params
.mode
||
952 can_compose_inline_
!= params
.can_compose_inline
||
953 text_input_flags_
!= params
.flags
) {
954 text_input_type_
= params
.type
;
955 text_input_mode_
= params
.mode
;
956 can_compose_inline_
= params
.can_compose_inline
;
957 text_input_flags_
= params
.flags
;
958 if (GetInputMethod())
959 GetInputMethod()->OnTextInputTypeChanged(this);
960 if (touch_editing_client_
)
961 touch_editing_client_
->OnTextInputTypeChanged(text_input_type_
);
963 if (params
.show_ime_if_needed
&& params
.type
!= ui::TEXT_INPUT_TYPE_NONE
) {
964 if (GetInputMethod())
965 GetInputMethod()->ShowImeIfNeeded();
969 void RenderWidgetHostViewAura::ImeCancelComposition() {
970 if (GetInputMethod())
971 GetInputMethod()->CancelComposition(this);
972 has_composition_text_
= false;
975 void RenderWidgetHostViewAura::ImeCompositionRangeChanged(
976 const gfx::Range
& range
,
977 const std::vector
<gfx::Rect
>& character_bounds
) {
978 composition_character_bounds_
= character_bounds
;
981 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status
,
983 UpdateCursorIfOverSelf();
987 void RenderWidgetHostViewAura::Destroy() {
988 // Beware, this function is not called on all destruction paths. It will
989 // implicitly end up calling ~RenderWidgetHostViewAura though, so all
990 // destruction/cleanup code should happen there, not here.
995 void RenderWidgetHostViewAura::SetTooltipText(
996 const base::string16
& tooltip_text
) {
997 tooltip_
= tooltip_text
;
998 aura::Window
* root_window
= window_
->GetRootWindow();
999 aura::client::TooltipClient
* tooltip_client
=
1000 aura::client::GetTooltipClient(root_window
);
1001 if (tooltip_client
) {
1002 tooltip_client
->UpdateTooltip(window_
);
1003 // Content tooltips should be visible indefinitely.
1004 tooltip_client
->SetTooltipShownTimeout(window_
, 0);
1008 void RenderWidgetHostViewAura::SelectionChanged(const base::string16
& text
,
1010 const gfx::Range
& range
) {
1011 RenderWidgetHostViewBase::SelectionChanged(text
, offset
, range
);
1013 #if defined(USE_X11) && !defined(OS_CHROMEOS)
1014 if (text
.empty() || range
.is_empty())
1016 size_t pos
= range
.GetMin() - offset
;
1017 size_t n
= range
.length();
1019 DCHECK(pos
+ n
<= text
.length()) << "The text can not fully cover range.";
1020 if (pos
>= text
.length()) {
1021 NOTREACHED() << "The text can not cover range.";
1025 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
1026 ui::ScopedClipboardWriter
clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION
);
1027 clipboard_writer
.WriteText(text
.substr(pos
, n
));
1028 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
1031 gfx::Size
RenderWidgetHostViewAura::GetRequestedRendererSize() const {
1032 return delegated_frame_host_
->GetRequestedRendererSize();
1035 void RenderWidgetHostViewAura::SelectionBoundsChanged(
1036 const ViewHostMsg_SelectionBounds_Params
& params
) {
1037 ui::SelectionBound anchor_bound
, focus_bound
;
1038 anchor_bound
.SetEdge(params
.anchor_rect
.origin(),
1039 params
.anchor_rect
.bottom_left());
1040 focus_bound
.SetEdge(params
.focus_rect
.origin(),
1041 params
.focus_rect
.bottom_left());
1043 if (params
.anchor_rect
== params
.focus_rect
) {
1044 anchor_bound
.set_type(ui::SelectionBound::CENTER
);
1045 focus_bound
.set_type(ui::SelectionBound::CENTER
);
1047 // Whether text is LTR at the anchor handle.
1048 bool anchor_LTR
= params
.anchor_dir
== blink::WebTextDirectionLeftToRight
;
1049 // Whether text is LTR at the focus handle.
1050 bool focus_LTR
= params
.focus_dir
== blink::WebTextDirectionLeftToRight
;
1052 if ((params
.is_anchor_first
&& anchor_LTR
) ||
1053 (!params
.is_anchor_first
&& !anchor_LTR
)) {
1054 anchor_bound
.set_type(ui::SelectionBound::LEFT
);
1056 anchor_bound
.set_type(ui::SelectionBound::RIGHT
);
1058 if ((params
.is_anchor_first
&& focus_LTR
) ||
1059 (!params
.is_anchor_first
&& !focus_LTR
)) {
1060 focus_bound
.set_type(ui::SelectionBound::RIGHT
);
1062 focus_bound
.set_type(ui::SelectionBound::LEFT
);
1066 if (anchor_bound
== selection_anchor_
&& focus_bound
== selection_focus_
)
1069 selection_anchor_
= anchor_bound
;
1070 selection_focus_
= focus_bound
;
1071 if (GetInputMethod())
1072 GetInputMethod()->OnCaretBoundsChanged(this);
1074 if (touch_editing_client_
) {
1075 touch_editing_client_
->OnSelectionOrCursorChanged(
1076 anchor_bound
, focus_bound
);
1080 void RenderWidgetHostViewAura::CopyFromCompositingSurface(
1081 const gfx::Rect
& src_subrect
,
1082 const gfx::Size
& dst_size
,
1083 ReadbackRequestCallback
& callback
,
1084 const SkColorType preferred_color_type
) {
1085 delegated_frame_host_
->CopyFromCompositingSurface(
1086 src_subrect
, dst_size
, callback
, preferred_color_type
);
1089 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceToVideoFrame(
1090 const gfx::Rect
& src_subrect
,
1091 const scoped_refptr
<media::VideoFrame
>& target
,
1092 const base::Callback
<void(bool)>& callback
) {
1093 delegated_frame_host_
->CopyFromCompositingSurfaceToVideoFrame(
1094 src_subrect
, target
, callback
);
1097 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const {
1098 return delegated_frame_host_
->CanCopyToVideoFrame();
1101 bool RenderWidgetHostViewAura::CanSubscribeFrame() const {
1102 return delegated_frame_host_
->CanSubscribeFrame();
1105 void RenderWidgetHostViewAura::BeginFrameSubscription(
1106 scoped_ptr
<RenderWidgetHostViewFrameSubscriber
> subscriber
) {
1107 delegated_frame_host_
->BeginFrameSubscription(subscriber
.Pass());
1110 void RenderWidgetHostViewAura::EndFrameSubscription() {
1111 delegated_frame_host_
->EndFrameSubscription();
1115 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
1116 return (legacy_render_widget_host_HWND_
!= NULL
);
1119 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects(
1120 const std::vector
<gfx::Rect
>& rects
) {
1121 // Check this before setting constrained_rects_, so that next time they're set
1122 // and we have a root window we don't early return.
1123 if (!window_
->GetHost())
1126 if (rects
== constrained_rects_
)
1129 constrained_rects_
= rects
;
1131 HWND parent
= window_
->GetHost()->GetAcceleratedWidget();
1132 CutoutRectsParams params
;
1133 params
.widget
= this;
1134 params
.cutout_rects
= constrained_rects_
;
1135 params
.geometry
= &plugin_window_moves_
;
1136 LPARAM lparam
= reinterpret_cast<LPARAM
>(¶ms
);
1137 EnumChildWindows(parent
, SetCutoutRectsCallback
, lparam
);
1140 void RenderWidgetHostViewAura::UpdateMouseLockRegion() {
1141 // Clip the cursor if chrome is running on regular desktop.
1142 if (gfx::Screen::GetScreenFor(window_
) == gfx::Screen::GetNativeScreen()) {
1144 gfx::win::DIPToScreenRect(window_
->GetBoundsInScreen()).ToRECT();
1145 ::ClipCursor(&window_rect
);
1149 void RenderWidgetHostViewAura::OnLegacyWindowDestroyed() {
1150 legacy_render_widget_host_HWND_
= NULL
;
1151 legacy_window_destroyed_
= true;
1155 void RenderWidgetHostViewAura::OnSwapCompositorFrame(
1156 uint32 output_surface_id
,
1157 scoped_ptr
<cc::CompositorFrame
> frame
) {
1158 TRACE_EVENT0("content", "RenderWidgetHostViewAura::OnSwapCompositorFrame");
1160 last_scroll_offset_
= frame
->metadata
.root_scroll_offset
;
1161 if (!frame
->delegated_frame_data
)
1163 delegated_frame_host_
->SwapDelegatedFrame(
1164 output_surface_id
, frame
->delegated_frame_data
.Pass(),
1165 frame
->metadata
.device_scale_factor
, frame
->metadata
.latency_info
,
1166 &frame
->metadata
.satisfies_sequences
);
1169 void RenderWidgetHostViewAura::DidStopFlinging() {
1170 if (touch_editing_client_
)
1171 touch_editing_client_
->DidStopFlinging();
1175 void RenderWidgetHostViewAura::SetParentNativeViewAccessible(
1176 gfx::NativeViewAccessible accessible_parent
) {
1179 gfx::NativeViewId
RenderWidgetHostViewAura::GetParentForWindowlessPlugin()
1181 if (legacy_render_widget_host_HWND_
) {
1182 return reinterpret_cast<gfx::NativeViewId
>(
1183 legacy_render_widget_host_HWND_
->hwnd());
1189 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
1190 const gfx::Size
& desired_size
) {
1191 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
1192 // matter what is returned here as GetBackingStore is the only caller of this
1193 // method. TODO(jbates) implement this if other Aura code needs it.
1197 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo
* results
) {
1198 GetScreenInfoForWindow(results
, window_
->GetRootWindow() ? window_
: NULL
);
1201 gfx::Rect
RenderWidgetHostViewAura::GetBoundsInRootWindow() {
1202 aura::Window
* top_level
= window_
->GetToplevelWindow();
1203 gfx::Rect
bounds(top_level
->GetBoundsInScreen());
1206 // TODO(zturner,iyengar): This will break when we remove support for NPAPI and
1207 // remove the legacy hwnd, so a better fix will need to be decided when that
1209 if (UsesNativeWindowFrame()) {
1210 // aura::Window doesn't take into account non-client area of native windows
1211 // (e.g. HWNDs), so for that case ask Windows directly what the bounds are.
1212 aura::WindowTreeHost
* host
= top_level
->GetHost();
1214 return top_level
->GetBoundsInScreen();
1215 RECT window_rect
= {0};
1216 HWND hwnd
= host
->GetAcceleratedWidget();
1217 ::GetWindowRect(hwnd
, &window_rect
);
1218 bounds
= gfx::Rect(window_rect
);
1220 // Maximized windows are outdented from the work area by the frame thickness
1221 // even though this "frame" is not painted. This confuses code (and people)
1222 // that think of a maximized window as corresponding exactly to the work
1223 // area. Correct for this by subtracting the frame thickness back off.
1224 if (::IsZoomed(hwnd
)) {
1225 bounds
.Inset(GetSystemMetrics(SM_CXSIZEFRAME
),
1226 GetSystemMetrics(SM_CYSIZEFRAME
));
1228 bounds
.Inset(GetSystemMetrics(SM_CXPADDEDBORDER
),
1229 GetSystemMetrics(SM_CXPADDEDBORDER
));
1233 bounds
= gfx::win::ScreenToDIPRect(bounds
);
1239 void RenderWidgetHostViewAura::WheelEventAck(
1240 const blink::WebMouseWheelEvent
& event
,
1241 InputEventAckState ack_result
) {
1242 if (overscroll_controller_
) {
1243 overscroll_controller_
->ReceivedEventACK(
1244 event
, (INPUT_EVENT_ACK_STATE_CONSUMED
== ack_result
));
1248 void RenderWidgetHostViewAura::GestureEventAck(
1249 const blink::WebGestureEvent
& event
,
1250 InputEventAckState ack_result
) {
1251 if (touch_editing_client_
)
1252 touch_editing_client_
->GestureEventAck(event
.type
);
1254 if (overscroll_controller_
) {
1255 overscroll_controller_
->ReceivedEventACK(
1256 event
, (INPUT_EVENT_ACK_STATE_CONSUMED
== ack_result
));
1260 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
1261 const TouchEventWithLatencyInfo
& touch
,
1262 InputEventAckState ack_result
) {
1263 ScopedVector
<ui::TouchEvent
> events
;
1264 aura::WindowTreeHost
* host
= window_
->GetHost();
1265 // |host| is NULL during tests.
1269 ui::EventResult result
= (ack_result
== INPUT_EVENT_ACK_STATE_CONSUMED
)
1273 blink::WebTouchPoint::State required_state
;
1274 switch (touch
.event
.type
) {
1275 case blink::WebInputEvent::TouchStart
:
1276 required_state
= blink::WebTouchPoint::StatePressed
;
1278 case blink::WebInputEvent::TouchEnd
:
1279 required_state
= blink::WebTouchPoint::StateReleased
;
1281 case blink::WebInputEvent::TouchMove
:
1282 required_state
= blink::WebTouchPoint::StateMoved
;
1284 case blink::WebInputEvent::TouchCancel
:
1285 required_state
= blink::WebTouchPoint::StateCancelled
;
1288 required_state
= blink::WebTouchPoint::StateUndefined
;
1293 // Only send acks for one changed touch point.
1294 bool sent_ack
= false;
1295 for (size_t i
= 0; i
< touch
.event
.touchesLength
; ++i
) {
1296 if (touch
.event
.touches
[i
].state
== required_state
) {
1298 host
->dispatcher()->ProcessedTouchEvent(touch
.event
.uniqueTouchEventId
,
1305 scoped_ptr
<SyntheticGestureTarget
>
1306 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1307 return scoped_ptr
<SyntheticGestureTarget
>(
1308 new SyntheticGestureTargetAura(host_
));
1311 InputEventAckState
RenderWidgetHostViewAura::FilterInputEvent(
1312 const blink::WebInputEvent
& input_event
) {
1313 bool consumed
= false;
1314 if (input_event
.type
== WebInputEvent::GestureFlingStart
) {
1315 const WebGestureEvent
& gesture_event
=
1316 static_cast<const WebGestureEvent
&>(input_event
);
1317 // Zero-velocity touchpad flings are an Aura-specific signal that the
1318 // touchpad scroll has ended, and should not be forwarded to the renderer.
1319 if (gesture_event
.sourceDevice
== blink::WebGestureDeviceTouchpad
&&
1320 !gesture_event
.data
.flingStart
.velocityX
&&
1321 !gesture_event
.data
.flingStart
.velocityY
) {
1326 if (overscroll_controller_
)
1327 consumed
|= overscroll_controller_
->WillHandleEvent(input_event
);
1329 // Touch events should always propagate to the renderer.
1330 if (WebTouchEvent::isTouchEventType(input_event
.type
))
1331 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED
;
1333 // Reporting consumed for a fling suggests that there's now an *active* fling
1334 // that requires both animation and a fling-end notification. However, the
1335 // OverscrollController consumes a fling to stop its propagation; it doesn't
1336 // actually tick a fling animation. Report no consumer to convey this.
1337 if (consumed
&& input_event
.type
== blink::WebInputEvent::GestureFlingStart
)
1338 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS
;
1340 return consumed
? INPUT_EVENT_ACK_STATE_CONSUMED
1341 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED
;
1344 BrowserAccessibilityManager
*
1345 RenderWidgetHostViewAura::CreateBrowserAccessibilityManager(
1346 BrowserAccessibilityDelegate
* delegate
) {
1347 BrowserAccessibilityManager
* manager
= NULL
;
1349 manager
= new BrowserAccessibilityManagerWin(
1350 BrowserAccessibilityManagerWin::GetEmptyDocument(), delegate
);
1352 manager
= BrowserAccessibilityManager::Create(
1353 BrowserAccessibilityManager::GetEmptyDocument(), delegate
);
1358 gfx::AcceleratedWidget
1359 RenderWidgetHostViewAura::AccessibilityGetAcceleratedWidget() {
1361 if (legacy_render_widget_host_HWND_
)
1362 return legacy_render_widget_host_HWND_
->hwnd();
1364 return gfx::kNullAcceleratedWidget
;
1367 gfx::NativeViewAccessible
1368 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() {
1370 if (legacy_render_widget_host_HWND_
)
1371 return legacy_render_widget_host_HWND_
->window_accessible();
1376 gfx::GLSurfaceHandle
RenderWidgetHostViewAura::GetCompositingSurface() {
1377 return ImageTransportFactory::GetInstance()->GetSharedSurfaceHandle();
1380 void RenderWidgetHostViewAura::ShowDisambiguationPopup(
1381 const gfx::Rect
& rect_pixels
,
1382 const SkBitmap
& zoomed_bitmap
) {
1383 RenderViewHostDelegate
* delegate
= NULL
;
1384 if (host_
->IsRenderView())
1385 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1386 // Suppress the link disambiguation popup if the virtual keyboard is currently
1387 // requested, as it doesn't interact well with the keyboard.
1388 if (delegate
&& delegate
->IsVirtualKeyboardRequested())
1391 // |target_rect| is provided in pixels, not DIPs. So we convert it to DIPs
1392 // by scaling it by the inverse of the device scale factor.
1393 gfx::RectF
screen_target_rect_f(rect_pixels
);
1394 screen_target_rect_f
.Scale(1.0f
/ current_device_scale_factor_
);
1395 disambiguation_target_rect_
= gfx::ToEnclosingRect(screen_target_rect_f
);
1397 float scale
= static_cast<float>(zoomed_bitmap
.width()) /
1398 static_cast<float>(rect_pixels
.width());
1399 gfx::Size
zoomed_size(gfx::ToCeiledSize(
1400 gfx::ScaleSize(disambiguation_target_rect_
.size(), scale
)));
1402 // Save of a copy of the |last_scroll_offset_| for comparison when the copy
1403 // callback fires, to ensure that we haven't scrolled.
1404 disambiguation_scroll_offset_
= last_scroll_offset_
;
1406 CopyFromCompositingSurface(
1407 disambiguation_target_rect_
,
1409 base::Bind(&RenderWidgetHostViewAura::DisambiguationPopupRendered
,
1410 weak_ptr_factory_
.GetWeakPtr()),
1414 void RenderWidgetHostViewAura::DisambiguationPopupRendered(
1415 const SkBitmap
& result
,
1416 ReadbackResponse response
) {
1417 if ((response
!= READBACK_SUCCESS
) ||
1418 disambiguation_scroll_offset_
!= last_scroll_offset_
)
1421 // Use RenderViewHostDelegate to get to the WebContentsViewAura, which will
1422 // actually show the disambiguation popup.
1423 RenderViewHostDelegate
* delegate
= NULL
;
1424 if (host_
->IsRenderView())
1425 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1426 RenderViewHostDelegateView
* delegate_view
= NULL
;
1428 delegate_view
= delegate
->GetDelegateView();
1429 if (delegate
->IsVirtualKeyboardRequested())
1432 if (delegate_view
) {
1433 delegate_view
->ShowDisambiguationPopup(
1434 disambiguation_target_rect_
,
1436 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationGesture
,
1437 weak_ptr_factory_
.GetWeakPtr()),
1438 base::Bind(&RenderWidgetHostViewAura::ProcessDisambiguationMouse
,
1439 weak_ptr_factory_
.GetWeakPtr()));
1443 void RenderWidgetHostViewAura::HideDisambiguationPopup() {
1444 RenderViewHostDelegate
* delegate
= NULL
;
1445 if (host_
->IsRenderView())
1446 delegate
= RenderViewHost::From(host_
)->GetDelegate();
1447 RenderViewHostDelegateView
* delegate_view
= NULL
;
1449 delegate_view
= delegate
->GetDelegateView();
1451 delegate_view
->HideDisambiguationPopup();
1454 void RenderWidgetHostViewAura::ProcessDisambiguationGesture(
1455 ui::GestureEvent
* event
) {
1456 blink::WebGestureEvent web_gesture
= content::MakeWebGestureEvent(*event
);
1457 // If we fail to make a WebGestureEvent that is a Tap from the provided event,
1458 // don't forward it to Blink.
1459 if (web_gesture
.type
< blink::WebInputEvent::Type::GestureTap
||
1460 web_gesture
.type
> blink::WebInputEvent::Type::GestureTapCancel
)
1463 host_
->ForwardGestureEvent(web_gesture
);
1466 void RenderWidgetHostViewAura::ProcessDisambiguationMouse(
1467 ui::MouseEvent
* event
) {
1468 blink::WebMouseEvent web_mouse
= content::MakeWebMouseEvent(*event
);
1469 host_
->ForwardMouseEvent(web_mouse
);
1472 bool RenderWidgetHostViewAura::LockMouse() {
1473 aura::Window
* root_window
= window_
->GetRootWindow();
1480 mouse_locked_
= true;
1481 #if !defined(OS_WIN)
1482 window_
->SetCapture();
1484 UpdateMouseLockRegion();
1486 aura::client::CursorClient
* cursor_client
=
1487 aura::client::GetCursorClient(root_window
);
1488 if (cursor_client
) {
1489 cursor_client
->HideCursor();
1490 cursor_client
->LockCursor();
1493 if (ShouldMoveToCenter()) {
1494 synthetic_move_sent_
= true;
1495 window_
->MoveCursorTo(gfx::Rect(window_
->bounds().size()).CenterPoint());
1497 tooltip_disabler_
.reset(new aura::client::ScopedTooltipDisabler(root_window
));
1501 void RenderWidgetHostViewAura::UnlockMouse() {
1502 tooltip_disabler_
.reset();
1504 aura::Window
* root_window
= window_
->GetRootWindow();
1505 if (!mouse_locked_
|| !root_window
)
1508 mouse_locked_
= false;
1510 #if !defined(OS_WIN)
1511 window_
->ReleaseCapture();
1515 window_
->MoveCursorTo(unlocked_mouse_position_
);
1516 aura::client::CursorClient
* cursor_client
=
1517 aura::client::GetCursorClient(root_window
);
1518 if (cursor_client
) {
1519 cursor_client
->UnlockCursor();
1520 cursor_client
->ShowCursor();
1523 host_
->LostMouseLock();
1526 ////////////////////////////////////////////////////////////////////////////////
1527 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
1528 void RenderWidgetHostViewAura::SetCompositionText(
1529 const ui::CompositionText
& composition
) {
1533 // TODO(suzhe): convert both renderer_host and renderer to use
1534 // ui::CompositionText.
1535 std::vector
<blink::WebCompositionUnderline
> underlines
;
1536 underlines
.reserve(composition
.underlines
.size());
1537 for (std::vector
<ui::CompositionUnderline
>::const_iterator it
=
1538 composition
.underlines
.begin();
1539 it
!= composition
.underlines
.end(); ++it
) {
1540 underlines
.push_back(
1541 blink::WebCompositionUnderline(static_cast<unsigned>(it
->start_offset
),
1542 static_cast<unsigned>(it
->end_offset
),
1545 it
->background_color
));
1548 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
1549 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
1550 host_
->ImeSetComposition(composition
.text
, underlines
,
1551 composition
.selection
.end(),
1552 composition
.selection
.end());
1554 has_composition_text_
= !composition
.text
.empty();
1557 void RenderWidgetHostViewAura::ConfirmCompositionText() {
1558 if (host_
&& has_composition_text_
) {
1559 host_
->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
1562 has_composition_text_
= false;
1565 void RenderWidgetHostViewAura::ClearCompositionText() {
1566 if (host_
&& has_composition_text_
)
1567 host_
->ImeCancelComposition();
1568 has_composition_text_
= false;
1571 void RenderWidgetHostViewAura::InsertText(const base::string16
& text
) {
1572 DCHECK(text_input_type_
!= ui::TEXT_INPUT_TYPE_NONE
);
1574 host_
->ImeConfirmComposition(text
, gfx::Range::InvalidRange(), false);
1575 has_composition_text_
= false;
1578 void RenderWidgetHostViewAura::InsertChar(base::char16 ch
, int flags
) {
1579 if (popup_child_host_view_
&& popup_child_host_view_
->NeedsInputGrab()) {
1580 popup_child_host_view_
->InsertChar(ch
, flags
);
1584 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1585 if (host_
&& (accept_return_character_
|| ch
!= ui::VKEY_RETURN
)) {
1586 double now
= ui::EventTimeForNow().InSecondsF();
1587 // Send a blink::WebInputEvent::Char event to |host_|.
1588 NativeWebKeyboardEvent
webkit_event(ui::ET_KEY_PRESSED
,
1593 ForwardKeyboardEvent(webkit_event
);
1597 ui::TextInputType
RenderWidgetHostViewAura::GetTextInputType() const {
1598 return text_input_type_
;
1601 ui::TextInputMode
RenderWidgetHostViewAura::GetTextInputMode() const {
1602 return text_input_mode_
;
1605 int RenderWidgetHostViewAura::GetTextInputFlags() const {
1606 return text_input_flags_
;
1609 bool RenderWidgetHostViewAura::CanComposeInline() const {
1610 return can_compose_inline_
;
1613 gfx::Rect
RenderWidgetHostViewAura::ConvertRectToScreen(
1614 const gfx::Rect
& rect
) const {
1615 gfx::Point origin
= rect
.origin();
1616 gfx::Point end
= gfx::Point(rect
.right(), rect
.bottom());
1618 aura::Window
* root_window
= window_
->GetRootWindow();
1621 aura::client::ScreenPositionClient
* screen_position_client
=
1622 aura::client::GetScreenPositionClient(root_window
);
1623 if (!screen_position_client
)
1625 screen_position_client
->ConvertPointToScreen(window_
, &origin
);
1626 screen_position_client
->ConvertPointToScreen(window_
, &end
);
1627 return gfx::Rect(origin
.x(),
1629 end
.x() - origin
.x(),
1630 end
.y() - origin
.y());
1633 gfx::Rect
RenderWidgetHostViewAura::ConvertRectFromScreen(
1634 const gfx::Rect
& rect
) const {
1635 gfx::Point origin
= rect
.origin();
1636 gfx::Point end
= gfx::Point(rect
.right(), rect
.bottom());
1638 aura::Window
* root_window
= window_
->GetRootWindow();
1640 aura::client::ScreenPositionClient
* screen_position_client
=
1641 aura::client::GetScreenPositionClient(root_window
);
1642 screen_position_client
->ConvertPointFromScreen(window_
, &origin
);
1643 screen_position_client
->ConvertPointFromScreen(window_
, &end
);
1644 return gfx::Rect(origin
.x(),
1646 end
.x() - origin
.x(),
1647 end
.y() - origin
.y());
1653 gfx::Rect
RenderWidgetHostViewAura::GetCaretBounds() const {
1655 ui::RectBetweenSelectionBounds(selection_anchor_
, selection_focus_
);
1656 return ConvertRectToScreen(rect
);
1659 bool RenderWidgetHostViewAura::GetCompositionCharacterBounds(
1661 gfx::Rect
* rect
) const {
1663 if (index
>= composition_character_bounds_
.size())
1665 *rect
= ConvertRectToScreen(composition_character_bounds_
[index
]);
1669 bool RenderWidgetHostViewAura::HasCompositionText() const {
1670 return has_composition_text_
;
1673 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range
* range
) const {
1674 range
->set_start(selection_text_offset_
);
1675 range
->set_end(selection_text_offset_
+ selection_text_
.length());
1679 bool RenderWidgetHostViewAura::GetCompositionTextRange(
1680 gfx::Range
* range
) const {
1681 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1686 bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range
* range
) const {
1687 range
->set_start(selection_range_
.start());
1688 range
->set_end(selection_range_
.end());
1692 bool RenderWidgetHostViewAura::SetSelectionRange(const gfx::Range
& range
) {
1693 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1698 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range
& range
) {
1699 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1704 bool RenderWidgetHostViewAura::GetTextFromRange(
1705 const gfx::Range
& range
,
1706 base::string16
* text
) const {
1707 gfx::Range
selection_text_range(selection_text_offset_
,
1708 selection_text_offset_
+ selection_text_
.length());
1710 if (!selection_text_range
.Contains(range
)) {
1714 if (selection_text_range
.EqualsIgnoringDirection(range
)) {
1715 // Avoid calling substr whose performance is low.
1716 *text
= selection_text_
;
1718 *text
= selection_text_
.substr(
1719 range
.GetMin() - selection_text_offset_
,
1725 void RenderWidgetHostViewAura::OnInputMethodChanged() {
1729 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
1733 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
1734 base::i18n::TextDirection direction
) {
1737 host_
->UpdateTextDirection(
1738 direction
== base::i18n::RIGHT_TO_LEFT
?
1739 blink::WebTextDirectionRightToLeft
:
1740 blink::WebTextDirectionLeftToRight
);
1741 host_
->NotifyTextDirection();
1745 void RenderWidgetHostViewAura::ExtendSelectionAndDelete(
1746 size_t before
, size_t after
) {
1747 RenderFrameHostImpl
* rfh
= GetFocusedFrame();
1749 rfh
->ExtendSelectionAndDelete(before
, after
);
1752 void RenderWidgetHostViewAura::EnsureCaretInRect(const gfx::Rect
& rect
) {
1753 gfx::Rect
intersected_rect(
1754 gfx::IntersectRects(rect
, window_
->GetBoundsInScreen()));
1756 if (intersected_rect
.IsEmpty())
1759 host_
->ScrollFocusedEditableNodeIntoRect(
1760 ConvertRectFromScreen(intersected_rect
));
1763 bool RenderWidgetHostViewAura::IsEditCommandEnabled(int command_id
) {
1767 void RenderWidgetHostViewAura::SetEditCommandForNextKeyEvent(int command_id
) {
1770 ////////////////////////////////////////////////////////////////////////////////
1771 // RenderWidgetHostViewAura, gfx::DisplayObserver implementation:
1773 void RenderWidgetHostViewAura::OnDisplayAdded(
1774 const gfx::Display
& new_display
) {
1777 void RenderWidgetHostViewAura::OnDisplayRemoved(
1778 const gfx::Display
& old_display
) {
1781 void RenderWidgetHostViewAura::OnDisplayMetricsChanged(
1782 const gfx::Display
& display
, uint32_t metrics
) {
1783 // The screen info should be updated regardless of the metric change.
1784 gfx::Screen
* screen
= gfx::Screen::GetScreenFor(window_
);
1785 if (display
.id() == screen
->GetDisplayNearestWindow(window_
).id()) {
1786 UpdateScreenInfo(window_
);
1787 current_cursor_
.SetDisplayInfo(display
);
1788 UpdateCursorIfOverSelf();
1792 ////////////////////////////////////////////////////////////////////////////////
1793 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
1795 gfx::Size
RenderWidgetHostViewAura::GetMinimumSize() const {
1799 gfx::Size
RenderWidgetHostViewAura::GetMaximumSize() const {
1803 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect
& old_bounds
,
1804 const gfx::Rect
& new_bounds
) {
1805 base::AutoReset
<bool> in_bounds_changed(&in_bounds_changed_
, true);
1806 // We care about this whenever RenderWidgetHostViewAura is not owned by a
1807 // WebContentsViewAura since changes to the Window's bounds need to be
1808 // messaged to the renderer. WebContentsViewAura invokes SetSize() or
1809 // SetBounds() itself. No matter how we got here, any redundant calls are
1811 SetSize(new_bounds
.size());
1813 if (GetInputMethod())
1814 GetInputMethod()->OnCaretBoundsChanged(this);
1817 gfx::NativeCursor
RenderWidgetHostViewAura::GetCursor(const gfx::Point
& point
) {
1819 return ui::kCursorNone
;
1820 return current_cursor_
.GetNativeCursor();
1823 int RenderWidgetHostViewAura::GetNonClientComponent(
1824 const gfx::Point
& point
) const {
1828 bool RenderWidgetHostViewAura::ShouldDescendIntoChildForEventHandling(
1829 aura::Window
* child
,
1830 const gfx::Point
& location
) {
1834 bool RenderWidgetHostViewAura::CanFocus() {
1835 return popup_type_
== blink::WebPopupTypeNone
;
1838 void RenderWidgetHostViewAura::OnCaptureLost() {
1839 host_
->LostCapture();
1840 if (touch_editing_client_
)
1841 touch_editing_client_
->EndTouchEditing(false);
1844 void RenderWidgetHostViewAura::OnPaint(const ui::PaintContext
& context
) {
1848 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
1849 float device_scale_factor
) {
1850 if (!host_
|| !window_
->GetRootWindow())
1853 UpdateScreenInfo(window_
);
1855 const gfx::Display display
= gfx::Screen::GetScreenFor(window_
)->
1856 GetDisplayNearestWindow(window_
);
1857 DCHECK_EQ(device_scale_factor
, display
.device_scale_factor());
1858 current_cursor_
.SetDisplayInfo(display
);
1859 SnapToPhysicalPixelBoundary();
1862 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window
* window
) {
1865 // If the tab was hidden and it's closed, host_->is_hidden would have been
1866 // reset to false in RenderWidgetHostImpl::RendererExited.
1867 if (!window_
->GetRootWindow() || host_
->is_hidden()) {
1868 parent
= ui::GetHiddenWindow();
1870 parent
= window_
->GetHost()->GetAcceleratedWidget();
1872 LPARAM lparam
= reinterpret_cast<LPARAM
>(this);
1873 EnumChildWindows(parent
, WindowDestroyingCallback
, lparam
);
1875 // The LegacyRenderWidgetHostHWND instance is destroyed when its window is
1876 // destroyed. Normally we control when that happens via the Destroy call
1877 // in the dtor. However there may be cases where the window is destroyed
1878 // by Windows, i.e. the parent window is destroyed before the
1879 // RenderWidgetHostViewAura instance goes away etc. To avoid that we
1880 // destroy the LegacyRenderWidgetHostHWND instance here.
1881 if (legacy_render_widget_host_HWND_
) {
1882 legacy_render_widget_host_HWND_
->set_host(NULL
);
1883 legacy_render_widget_host_HWND_
->Destroy();
1884 // The Destroy call above will delete the LegacyRenderWidgetHostHWND
1886 legacy_render_widget_host_HWND_
= NULL
;
1890 // Make sure that the input method no longer references to this object before
1891 // this object is removed from the root window (i.e. this object loses access
1892 // to the input method).
1893 ui::InputMethod
* input_method
= GetInputMethod();
1895 input_method
->DetachTextInputClient(this);
1897 if (overscroll_controller_
)
1898 overscroll_controller_
->Reset();
1901 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window
* window
) {
1902 // Ask the RWH to drop reference to us.
1903 if (!is_guest_view_hack_
)
1904 host_
->ViewDestroyed();
1909 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible
) {
1912 bool RenderWidgetHostViewAura::HasHitTestMask() const {
1916 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path
* mask
) const {
1919 ////////////////////////////////////////////////////////////////////////////////
1920 // RenderWidgetHostViewAura, ui::EventHandler implementation:
1922 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent
* event
) {
1923 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent");
1924 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
1927 if (popup_child_host_view_
&& popup_child_host_view_
->NeedsInputGrab()) {
1928 popup_child_host_view_
->OnKeyEvent(event
);
1929 if (event
->handled())
1933 // We need to handle the Escape key for Pepper Flash.
1934 if (is_fullscreen_
&& event
->key_code() == ui::VKEY_ESCAPE
) {
1935 // Focus the window we were created from.
1936 if (host_tracker_
.get() && !host_tracker_
->windows().empty()) {
1937 aura::Window
* host
= *(host_tracker_
->windows().begin());
1938 aura::client::FocusClient
* client
= aura::client::GetFocusClient(host
);
1940 // Calling host->Focus() may delete |this|. We create a local observer
1941 // for that. In that case we exit without further access to any members.
1942 aura::WindowTracker tracker
;
1943 aura::Window
* window
= window_
;
1944 tracker
.Add(window
);
1946 if (!tracker
.Contains(window
)) {
1947 event
->SetHandled();
1954 if (event
->key_code() == ui::VKEY_RETURN
) {
1955 // Do not forward return key release events if no press event was handled.
1956 if (event
->type() == ui::ET_KEY_RELEASED
&& !accept_return_character_
)
1958 // Accept return key character events between press and release events.
1959 accept_return_character_
= event
->type() == ui::ET_KEY_PRESSED
;
1962 // We don't have to communicate with an input method here.
1963 NativeWebKeyboardEvent
webkit_event(*event
);
1964 ForwardKeyboardEvent(webkit_event
);
1966 event
->SetHandled();
1969 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent
* event
) {
1970 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent");
1972 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
1975 if (mouse_locked_
) {
1976 aura::client::CursorClient
* cursor_client
=
1977 aura::client::GetCursorClient(window_
->GetRootWindow());
1978 DCHECK(!cursor_client
|| !cursor_client
->IsCursorVisible());
1980 if (event
->type() == ui::ET_MOUSEWHEEL
) {
1981 blink::WebMouseWheelEvent mouse_wheel_event
=
1982 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent
&>(*event
));
1983 if (mouse_wheel_event
.deltaX
!= 0 || mouse_wheel_event
.deltaY
!= 0)
1984 host_
->ForwardWheelEvent(mouse_wheel_event
);
1988 gfx::Point
center(gfx::Rect(window_
->bounds().size()).CenterPoint());
1990 // If we receive non client mouse messages while we are in the locked state
1991 // it probably means that the mouse left the borders of our window and
1992 // needs to be moved back to the center.
1993 if (event
->flags() & ui::EF_IS_NON_CLIENT
) {
1994 synthetic_move_sent_
= true;
1995 window_
->MoveCursorTo(center
);
1999 blink::WebMouseEvent mouse_event
= MakeWebMouseEvent(*event
);
2001 bool is_move_to_center_event
= (event
->type() == ui::ET_MOUSE_MOVED
||
2002 event
->type() == ui::ET_MOUSE_DRAGGED
) &&
2003 mouse_event
.x
== center
.x() && mouse_event
.y
== center
.y();
2005 // For fractional scale factors, the conversion from pixels to dip and
2006 // vice versa could result in off by 1 or 2 errors which hurts us because
2007 // we want to avoid sending the artificial move to center event to the
2008 // renderer. Sending the move to center to the renderer cause the cursor
2009 // to bounce around the center of the screen leading to the lock operation
2010 // not working correctly.
2011 // Workaround is to treat a mouse move or drag event off by at most 2 px
2012 // from the center as a move to center event.
2013 if (synthetic_move_sent_
&&
2014 IsFractionalScaleFactor(current_device_scale_factor_
)) {
2015 if (event
->type() == ui::ET_MOUSE_MOVED
||
2016 event
->type() == ui::ET_MOUSE_DRAGGED
) {
2017 if ((abs(mouse_event
.x
- center
.x()) <= 2) &&
2018 (abs(mouse_event
.y
- center
.y()) <= 2)) {
2019 is_move_to_center_event
= true;
2024 ModifyEventMovementAndCoords(&mouse_event
);
2026 bool should_not_forward
= is_move_to_center_event
&& synthetic_move_sent_
;
2027 if (should_not_forward
) {
2028 synthetic_move_sent_
= false;
2030 // Check if the mouse has reached the border and needs to be centered.
2031 if (ShouldMoveToCenter()) {
2032 synthetic_move_sent_
= true;
2033 window_
->MoveCursorTo(center
);
2035 bool is_selection_popup
= popup_child_host_view_
&&
2036 popup_child_host_view_
->NeedsInputGrab();
2037 // Forward event to renderer.
2038 if (CanRendererHandleEvent(event
, mouse_locked_
, is_selection_popup
) &&
2039 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2040 host_
->ForwardMouseEvent(mouse_event
);
2041 // Ensure that we get keyboard focus on mouse down as a plugin window
2042 // may have grabbed keyboard focus.
2043 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2050 // As the overscroll is handled during scroll events from the trackpad, the
2051 // RWHVA window is transformed by the overscroll controller. This transform
2052 // triggers a synthetic mouse-move event to be generated (by the aura
2053 // RootWindow). But this event interferes with the overscroll gesture. So,
2054 // ignore such synthetic mouse-move events if an overscroll gesture is in
2056 if (overscroll_controller_
&&
2057 overscroll_controller_
->overscroll_mode() != OVERSCROLL_NONE
&&
2058 event
->flags() & ui::EF_IS_SYNTHESIZED
&&
2059 (event
->type() == ui::ET_MOUSE_ENTERED
||
2060 event
->type() == ui::ET_MOUSE_EXITED
||
2061 event
->type() == ui::ET_MOUSE_MOVED
)) {
2062 event
->StopPropagation();
2066 if (event
->type() == ui::ET_MOUSEWHEEL
) {
2068 // We get mouse wheel/scroll messages even if we are not in the foreground.
2069 // So here we check if we have any owned popup windows in the foreground and
2071 aura::WindowTreeHost
* host
= window_
->GetHost();
2073 HWND parent
= host
->GetAcceleratedWidget();
2074 HWND toplevel_hwnd
= ::GetAncestor(parent
, GA_ROOT
);
2075 EnumThreadWindows(GetCurrentThreadId(),
2077 reinterpret_cast<LPARAM
>(toplevel_hwnd
));
2080 // The Disambiguation popup does not parent itself from this window, so we
2081 // manually dismiss it.
2082 HideDisambiguationPopup();
2084 blink::WebMouseWheelEvent mouse_wheel_event
=
2085 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent
&>(*event
));
2086 if (mouse_wheel_event
.deltaX
!= 0 || mouse_wheel_event
.deltaY
!= 0)
2087 host_
->ForwardWheelEvent(mouse_wheel_event
);
2089 bool is_selection_popup
= popup_child_host_view_
&&
2090 popup_child_host_view_
->NeedsInputGrab();
2091 if (CanRendererHandleEvent(event
, mouse_locked_
, is_selection_popup
) &&
2092 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2093 // Confirm existing composition text on mouse press, to make sure
2094 // the input caret won't be moved with an ongoing composition text.
2095 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2096 FinishImeCompositionSession();
2098 blink::WebMouseEvent mouse_event
= MakeWebMouseEvent(*event
);
2099 ModifyEventMovementAndCoords(&mouse_event
);
2100 host_
->ForwardMouseEvent(mouse_event
);
2101 // Ensure that we get keyboard focus on mouse down as a plugin window may
2102 // have grabbed keyboard focus.
2103 if (event
->type() == ui::ET_MOUSE_PRESSED
)
2108 switch (event
->type()) {
2109 case ui::ET_MOUSE_PRESSED
:
2110 window_
->SetCapture();
2112 case ui::ET_MOUSE_RELEASED
:
2113 if (!NeedsMouseCapture())
2114 window_
->ReleaseCapture();
2120 // Needed to propagate mouse event to |window_->parent()->delegate()|, but
2121 // note that it might be something other than a WebContentsViewAura instance.
2122 // TODO(pkotwicz): Find a better way of doing this.
2123 // In fullscreen mode which is typically used by flash, don't forward
2124 // the mouse events to the parent. The renderer and the plugin process
2125 // handle these events.
2126 if (!is_fullscreen_
&& window_
->parent() && window_
->parent()->delegate() &&
2127 !(event
->flags() & ui::EF_FROM_TOUCH
)) {
2128 event
->ConvertLocationToTarget(window_
, window_
->parent());
2129 window_
->parent()->delegate()->OnMouseEvent(event
);
2132 if (!IsXButtonUpEvent(event
))
2133 event
->SetHandled();
2136 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent
* event
) {
2137 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent");
2138 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
2141 if (event
->type() == ui::ET_SCROLL
) {
2142 #if !defined(OS_WIN)
2144 // Investigate if this is true for Windows 8 Metro ASH as well.
2145 if (event
->finger_count() != 2)
2148 blink::WebGestureEvent gesture_event
=
2149 MakeWebGestureEventFlingCancel();
2150 host_
->ForwardGestureEvent(gesture_event
);
2151 blink::WebMouseWheelEvent mouse_wheel_event
=
2152 MakeWebMouseWheelEvent(*event
);
2153 host_
->ForwardWheelEvent(mouse_wheel_event
);
2154 RecordAction(base::UserMetricsAction("TrackpadScroll"));
2155 } else if (event
->type() == ui::ET_SCROLL_FLING_START
||
2156 event
->type() == ui::ET_SCROLL_FLING_CANCEL
) {
2157 blink::WebGestureEvent gesture_event
= MakeWebGestureEvent(*event
);
2158 host_
->ForwardGestureEvent(gesture_event
);
2159 if (event
->type() == ui::ET_SCROLL_FLING_START
)
2160 RecordAction(base::UserMetricsAction("TrackpadScrollFling"));
2163 event
->SetHandled();
2166 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent
* event
) {
2167 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent");
2168 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
2171 // Update the touch event first.
2172 if (!pointer_state_
.OnTouch(*event
)) {
2173 event
->StopPropagation();
2177 blink::WebTouchEvent touch_event
= ui::CreateWebTouchEventFromMotionEvent(
2178 pointer_state_
, event
->may_cause_scrolling());
2179 pointer_state_
.CleanupRemovedTouchPoints(*event
);
2181 // It is important to always mark events as being handled asynchronously when
2182 // they are forwarded. This ensures that the current event does not get
2183 // processed by the gesture recognizer before events currently awaiting
2184 // dispatch in the touch queue.
2185 event
->DisableSynchronousHandling();
2187 // Set unchanged touch point to StateStationary for touchmove and
2188 // touchcancel to make sure only send one ack per WebTouchEvent.
2189 MarkUnchangedTouchPointsAsStationary(&touch_event
, event
->touch_id());
2190 host_
->ForwardTouchEventWithLatencyInfo(touch_event
, *event
->latency());
2193 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent
* event
) {
2194 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent");
2195 if ((event
->type() == ui::ET_GESTURE_PINCH_BEGIN
||
2196 event
->type() == ui::ET_GESTURE_PINCH_UPDATE
||
2197 event
->type() == ui::ET_GESTURE_PINCH_END
) && !pinch_zoom_enabled_
) {
2198 event
->SetHandled();
2202 if (touch_editing_client_
&& touch_editing_client_
->HandleInputEvent(event
))
2205 // Confirm existing composition text on TAP gesture, to make sure the input
2206 // caret won't be moved with an ongoing composition text.
2207 if (event
->type() == ui::ET_GESTURE_TAP
)
2208 FinishImeCompositionSession();
2210 blink::WebGestureEvent gesture
= MakeWebGestureEvent(*event
);
2211 if (event
->type() == ui::ET_GESTURE_TAP_DOWN
) {
2212 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an
2213 // event to stop any in-progress flings.
2214 blink::WebGestureEvent fling_cancel
= gesture
;
2215 fling_cancel
.type
= blink::WebInputEvent::GestureFlingCancel
;
2216 fling_cancel
.sourceDevice
= blink::WebGestureDeviceTouchscreen
;
2217 host_
->ForwardGestureEvent(fling_cancel
);
2220 if (gesture
.type
!= blink::WebInputEvent::Undefined
) {
2221 host_
->ForwardGestureEventWithLatencyInfo(gesture
, *event
->latency());
2223 if (event
->type() == ui::ET_GESTURE_SCROLL_BEGIN
||
2224 event
->type() == ui::ET_GESTURE_SCROLL_UPDATE
||
2225 event
->type() == ui::ET_GESTURE_SCROLL_END
) {
2226 RecordAction(base::UserMetricsAction("TouchscreenScroll"));
2227 } else if (event
->type() == ui::ET_SCROLL_FLING_START
) {
2228 RecordAction(base::UserMetricsAction("TouchscreenScrollFling"));
2232 // If a gesture is not processed by the webpage, then WebKit processes it
2233 // (e.g. generates synthetic mouse events).
2234 event
->SetHandled();
2237 ////////////////////////////////////////////////////////////////////////////////
2238 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation:
2240 bool RenderWidgetHostViewAura::ShouldActivate() const {
2241 aura::WindowTreeHost
* host
= window_
->GetHost();
2244 const ui::Event
* event
= host
->dispatcher()->current_event();
2247 return is_fullscreen_
;
2250 ////////////////////////////////////////////////////////////////////////////////
2251 // RenderWidgetHostViewAura, aura::client::CursorClientObserver implementation:
2253 void RenderWidgetHostViewAura::OnCursorVisibilityChanged(bool is_visible
) {
2254 NotifyRendererOfCursorVisibilityState(is_visible
);
2257 ////////////////////////////////////////////////////////////////////////////////
2258 // RenderWidgetHostViewAura, aura::client::FocusChangeObserver implementation:
2260 void RenderWidgetHostViewAura::OnWindowFocused(aura::Window
* gained_focus
,
2261 aura::Window
* lost_focus
) {
2262 DCHECK(window_
== gained_focus
|| window_
== lost_focus
);
2263 if (window_
== gained_focus
) {
2264 // We need to honor input bypass if the associated tab is does not want
2265 // input. This gives the current focused window a chance to be the text
2266 // input client and handle events.
2267 if (host_
->ignore_input_events())
2271 host_
->SetActive(true);
2273 ui::InputMethod
* input_method
= GetInputMethod();
2275 // Ask the system-wide IME to send all TextInputClient messages to |this|
2277 input_method
->SetFocusedTextInputClient(this);
2279 // Often the application can set focus to the view in response to a key
2280 // down. However the following char event shouldn't be sent to the web
2282 host_
->SuppressNextCharEvents();
2285 BrowserAccessibilityManager
* manager
=
2286 host_
->GetRootBrowserAccessibilityManager();
2288 manager
->OnWindowFocused();
2289 } else if (window_
== lost_focus
) {
2290 host_
->SetActive(false);
2293 DetachFromInputMethod();
2295 if (touch_editing_client_
)
2296 touch_editing_client_
->EndTouchEditing(false);
2298 if (overscroll_controller_
)
2299 overscroll_controller_
->Cancel();
2301 BrowserAccessibilityManager
* manager
=
2302 host_
->GetRootBrowserAccessibilityManager();
2304 manager
->OnWindowBlurred();
2306 // If we lose the focus while fullscreen, close the window; Pepper Flash
2307 // won't do it for us (unlike NPAPI Flash). However, we do not close the
2308 // window if we lose the focus to a window on another display.
2309 gfx::Screen
* screen
= gfx::Screen::GetScreenFor(window_
);
2310 bool focusing_other_display
=
2311 gained_focus
&& screen
->GetNumDisplays() > 1 &&
2312 (screen
->GetDisplayNearestWindow(window_
).id() !=
2313 screen
->GetDisplayNearestWindow(gained_focus
).id());
2314 if (is_fullscreen_
&& !in_shutdown_
&& !focusing_other_display
) {
2316 // On Windows, if we are switching to a non Aura Window on a different
2317 // screen we should not close the fullscreen window.
2318 if (!gained_focus
) {
2320 ::GetCursorPos(&point
);
2321 if (screen
->GetDisplayNearestWindow(window_
).id() !=
2322 screen
->GetDisplayNearestPoint(gfx::Point(point
)).id())
2330 // Close the child popup window if we lose focus (e.g. due to a JS alert or
2331 // system modal dialog). This is particularly important if
2332 // |popup_child_host_view_| has mouse capture.
2333 if (popup_child_host_view_
)
2334 popup_child_host_view_
->Shutdown();
2338 ////////////////////////////////////////////////////////////////////////////////
2339 // RenderWidgetHostViewAura, aura::WindowTreeHostObserver implementation:
2341 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost
* host
,
2342 const gfx::Point
& new_origin
) {
2343 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved",
2344 "new_origin", new_origin
.ToString());
2346 UpdateScreenInfo(window_
);
2349 ////////////////////////////////////////////////////////////////////////////////
2350 // RenderWidgetHostViewAura, private:
2352 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
2353 if (touch_editing_client_
)
2354 touch_editing_client_
->OnViewDestroyed();
2356 delegated_frame_host_
.reset();
2357 window_observer_
.reset();
2358 if (window_
->GetHost())
2359 window_
->GetHost()->RemoveObserver(this);
2361 if (popup_parent_host_view_
) {
2362 DCHECK(popup_parent_host_view_
->popup_child_host_view_
== NULL
||
2363 popup_parent_host_view_
->popup_child_host_view_
== this);
2364 popup_parent_host_view_
->popup_child_host_view_
= NULL
;
2366 if (popup_child_host_view_
) {
2367 DCHECK(popup_child_host_view_
->popup_parent_host_view_
== NULL
||
2368 popup_child_host_view_
->popup_parent_host_view_
== this);
2369 popup_child_host_view_
->popup_parent_host_view_
= NULL
;
2371 event_filter_for_popup_exit_
.reset();
2372 aura::client::SetTooltipText(window_
, NULL
);
2373 gfx::Screen::GetScreenFor(window_
)->RemoveObserver(this);
2375 // This call is usually no-op since |this| object is already removed from the
2376 // Aura root window and we don't have a way to get an input method object
2377 // associated with the window, but just in case.
2378 DetachFromInputMethod();
2381 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2382 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2384 DCHECK(!legacy_render_widget_host_HWND_
);
2388 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
2389 aura::Window
* root_window
= window_
->GetRootWindow();
2393 gfx::Point root_window_point
=
2394 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint();
2395 aura::client::ScreenPositionClient
* screen_position_client
=
2396 aura::client::GetScreenPositionClient(root_window
);
2397 if (screen_position_client
) {
2398 screen_position_client
->ConvertPointFromScreen(
2399 root_window
, &root_window_point
);
2402 if (root_window
->GetEventHandlerForPoint(root_window_point
) != window_
)
2405 gfx::NativeCursor cursor
= current_cursor_
.GetNativeCursor();
2406 // Do not show loading cursor when the cursor is currently hidden.
2407 if (is_loading_
&& cursor
!= ui::kCursorNone
)
2408 cursor
= ui::kCursorPointer
;
2410 aura::client::CursorClient
* cursor_client
=
2411 aura::client::GetCursorClient(root_window
);
2412 if (cursor_client
) {
2413 cursor_client
->SetCursor(cursor
);
2417 ui::InputMethod
* RenderWidgetHostViewAura::GetInputMethod() const {
2418 aura::Window
* root_window
= window_
->GetRootWindow();
2421 return root_window
->GetHost()->GetInputMethod();
2424 void RenderWidgetHostViewAura::Shutdown() {
2425 if (!in_shutdown_
) {
2426 in_shutdown_
= true;
2431 bool RenderWidgetHostViewAura::NeedsInputGrab() {
2432 return popup_type_
== blink::WebPopupTypePage
;
2435 bool RenderWidgetHostViewAura::NeedsMouseCapture() {
2436 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2437 return NeedsInputGrab();
2442 void RenderWidgetHostViewAura::FinishImeCompositionSession() {
2443 if (!has_composition_text_
)
2446 host_
->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
2449 ImeCancelComposition();
2452 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords(
2453 blink::WebMouseEvent
* event
) {
2454 // If the mouse has just entered, we must report zero movementX/Y. Hence we
2455 // reset any global_mouse_position set previously.
2456 if (event
->type
== blink::WebInputEvent::MouseEnter
||
2457 event
->type
== blink::WebInputEvent::MouseLeave
)
2458 global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2460 // Movement is computed by taking the difference of the new cursor position
2461 // and the previous. Under mouse lock the cursor will be warped back to the
2462 // center so that we are not limited by clipping boundaries.
2463 // We do not measure movement as the delta from cursor to center because
2464 // we may receive more mouse movement events before our warp has taken
2466 event
->movementX
= event
->globalX
- global_mouse_position_
.x();
2467 event
->movementY
= event
->globalY
- global_mouse_position_
.y();
2469 global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2471 // Under mouse lock, coordinates of mouse are locked to what they were when
2472 // mouse lock was entered.
2473 if (mouse_locked_
) {
2474 event
->x
= unlocked_mouse_position_
.x();
2475 event
->y
= unlocked_mouse_position_
.y();
2476 event
->windowX
= unlocked_mouse_position_
.x();
2477 event
->windowY
= unlocked_mouse_position_
.y();
2478 event
->globalX
= unlocked_global_mouse_position_
.x();
2479 event
->globalY
= unlocked_global_mouse_position_
.y();
2481 unlocked_mouse_position_
.SetPoint(event
->x
, event
->y
);
2482 unlocked_global_mouse_position_
.SetPoint(event
->globalX
, event
->globalY
);
2486 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState(
2488 if (host_
->is_hidden() ||
2489 (cursor_visibility_state_in_renderer_
== VISIBLE
&& is_visible
) ||
2490 (cursor_visibility_state_in_renderer_
== NOT_VISIBLE
&& !is_visible
))
2493 cursor_visibility_state_in_renderer_
= is_visible
? VISIBLE
: NOT_VISIBLE
;
2494 host_
->SendCursorVisibilityState(is_visible
);
2497 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled
) {
2499 overscroll_controller_
.reset();
2500 else if (!overscroll_controller_
)
2501 overscroll_controller_
.reset(new OverscrollController());
2504 void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() {
2505 // The top left corner of our view in window coordinates might not land on a
2506 // device pixel boundary if we have a non-integer device scale. In that case,
2507 // to avoid the web contents area looking blurry we translate the web contents
2508 // in the +x, +y direction to land on the nearest pixel boundary. This may
2509 // cause the bottom and right edges to be clipped slightly, but that's ok.
2510 aura::Window
* snapped
= NULL
;
2511 // On desktop, use the root window. On alternative environment (ash),
2512 // use the toplevel window which must be already snapped.
2513 if (gfx::Screen::GetScreenFor(window_
) !=
2514 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE
)) {
2515 snapped
= window_
->GetRootWindow();
2517 snapped
= window_
->GetToplevelWindow();
2519 if (snapped
&& snapped
!= window_
)
2520 ui::SnapLayerToPhysicalPixelBoundary(snapped
->layer(), window_
->layer());
2522 has_snapped_to_boundary_
= true;
2525 void RenderWidgetHostViewAura::OnShowContextMenu() {
2527 showing_context_menu_
= true;
2531 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect
& rect
) {
2532 SnapToPhysicalPixelBoundary();
2533 // Don't recursively call SetBounds if this bounds update is the result of
2534 // a Window::SetBoundsInternal call.
2535 if (!in_bounds_changed_
)
2536 window_
->SetBounds(rect
);
2537 host_
->WasResized();
2538 delegated_frame_host_
->WasResized();
2539 if (touch_editing_client_
) {
2540 touch_editing_client_
->OnSelectionOrCursorChanged(selection_anchor_
,
2544 // Create the legacy dummy window which corresponds to the bounds of the
2545 // webcontents. This will be passed as the container window for windowless
2547 // Plugins like Flash assume the container window which is returned via the
2548 // NPNVnetscapeWindow property corresponds to the bounds of the webpage.
2549 // This is not true in Aura where we have only HWND which is the main Aura
2550 // window. If we return this window to plugins like Flash then it causes the
2551 // coordinate translations done by these plugins to break.
2552 // Additonally the legacy dummy window is needed for accessibility and for
2553 // scrolling to work in legacy drivers for trackpoints/trackpads, etc.
2554 if (!legacy_window_destroyed_
&& GetNativeViewId()) {
2555 if (!legacy_render_widget_host_HWND_
) {
2556 legacy_render_widget_host_HWND_
= LegacyRenderWidgetHostHWND::Create(
2557 reinterpret_cast<HWND
>(GetNativeViewId()));
2559 if (legacy_render_widget_host_HWND_
) {
2560 legacy_render_widget_host_HWND_
->set_host(this);
2561 legacy_render_widget_host_HWND_
->SetBounds(
2562 window_
->GetBoundsInRootWindow());
2563 // There are cases where the parent window is created, made visible and
2564 // the associated RenderWidget is also visible before the
2565 // LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown
2567 if (!host_
->is_hidden())
2568 legacy_render_widget_host_HWND_
->Show();
2573 UpdateMouseLockRegion();
2577 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip(
2578 const gfx::Rect
& rect
,
2579 const gfx::Rect
& clip
) {
2580 if (!clip
.IsEmpty()) {
2581 gfx::Rect to_paint
= gfx::SubtractRects(rect
, clip
);
2582 if (!to_paint
.IsEmpty())
2583 window_
->SchedulePaintInRect(to_paint
);
2585 window_
->SchedulePaintInRect(rect
);
2589 bool RenderWidgetHostViewAura::ShouldMoveToCenter() {
2590 gfx::Rect rect
= window_
->bounds();
2591 rect
= ConvertRectToScreen(rect
);
2592 int border_x
= rect
.width() * kMouseLockBorderPercentage
/ 100;
2593 int border_y
= rect
.height() * kMouseLockBorderPercentage
/ 100;
2595 return global_mouse_position_
.x() < rect
.x() + border_x
||
2596 global_mouse_position_
.x() > rect
.right() - border_x
||
2597 global_mouse_position_
.y() < rect
.y() + border_y
||
2598 global_mouse_position_
.y() > rect
.bottom() - border_y
;
2601 void RenderWidgetHostViewAura::AddedToRootWindow() {
2602 window_
->GetHost()->AddObserver(this);
2603 UpdateScreenInfo(window_
);
2605 aura::client::CursorClient
* cursor_client
=
2606 aura::client::GetCursorClient(window_
->GetRootWindow());
2607 if (cursor_client
) {
2608 cursor_client
->AddObserver(this);
2609 NotifyRendererOfCursorVisibilityState(cursor_client
->IsCursorVisible());
2612 ui::InputMethod
* input_method
= GetInputMethod();
2614 input_method
->SetFocusedTextInputClient(this);
2618 // The parent may have changed here. Ensure that the legacy window is
2619 // reparented accordingly.
2620 if (legacy_render_widget_host_HWND_
)
2621 legacy_render_widget_host_HWND_
->UpdateParent(
2622 reinterpret_cast<HWND
>(GetNativeViewId()));
2625 delegated_frame_host_
->SetCompositor(window_
->GetHost()->compositor());
2626 if (window_
->GetHost()->compositor())
2627 begin_frame_observer_proxy_
.SetCompositor(window_
->GetHost()->compositor());
2630 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2631 aura::client::CursorClient
* cursor_client
=
2632 aura::client::GetCursorClient(window_
->GetRootWindow());
2634 cursor_client
->RemoveObserver(this);
2636 DetachFromInputMethod();
2638 window_
->GetHost()->RemoveObserver(this);
2639 delegated_frame_host_
->ResetCompositor();
2640 begin_frame_observer_proxy_
.ResetCompositor();
2643 // Update the legacy window's parent temporarily to the desktop window. It
2644 // will eventually get reparented to the right root.
2645 if (legacy_render_widget_host_HWND_
)
2646 legacy_render_widget_host_HWND_
->UpdateParent(::GetDesktopWindow());
2650 void RenderWidgetHostViewAura::DetachFromInputMethod() {
2651 ui::InputMethod
* input_method
= GetInputMethod();
2653 input_method
->DetachTextInputClient(this);
2656 void RenderWidgetHostViewAura::ForwardKeyboardEvent(
2657 const NativeWebKeyboardEvent
& event
) {
2658 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2659 ui::TextEditKeyBindingsDelegateAuraLinux
* keybinding_delegate
=
2660 ui::GetTextEditKeyBindingsDelegate();
2661 std::vector
<ui::TextEditCommandAuraLinux
> commands
;
2662 if (!event
.skip_in_browser
&&
2663 keybinding_delegate
&&
2665 keybinding_delegate
->MatchEvent(*event
.os_event
, &commands
)) {
2666 // Transform from ui/ types to content/ types.
2667 EditCommands edit_commands
;
2668 for (std::vector
<ui::TextEditCommandAuraLinux
>::const_iterator it
=
2669 commands
.begin(); it
!= commands
.end(); ++it
) {
2670 edit_commands
.push_back(EditCommand(it
->GetCommandString(),
2673 host_
->Send(new InputMsg_SetEditCommandsForNextKeyEvent(
2674 host_
->GetRoutingID(), edit_commands
));
2675 NativeWebKeyboardEvent
copy_event(event
);
2676 copy_event
.match_edit_command
= true;
2677 host_
->ForwardKeyboardEvent(copy_event
);
2682 host_
->ForwardKeyboardEvent(event
);
2685 ////////////////////////////////////////////////////////////////////////////////
2686 // DelegatedFrameHost, public:
2688 ui::Layer
* RenderWidgetHostViewAura::DelegatedFrameHostGetLayer() const {
2689 return window_
->layer();
2692 bool RenderWidgetHostViewAura::DelegatedFrameHostIsVisible() const {
2693 return !host_
->is_hidden();
2696 gfx::Size
RenderWidgetHostViewAura::DelegatedFrameHostDesiredSizeInDIP() const {
2697 return window_
->bounds().size();
2700 bool RenderWidgetHostViewAura::DelegatedFrameCanCreateResizeLock() const {
2701 #if !defined(OS_CHROMEOS)
2702 // On Windows and Linux, holding pointer moves will not help throttling
2704 // TODO(piman): on Windows we need to block (nested message loop?) the
2705 // WM_SIZE event. On Linux we need to throttle at the WM level using
2706 // _NET_WM_SYNC_REQUEST.
2709 if (host_
->auto_resize_enabled())
2715 scoped_ptr
<ResizeLock
>
2716 RenderWidgetHostViewAura::DelegatedFrameHostCreateResizeLock(
2717 bool defer_compositor_lock
) {
2718 gfx::Size desired_size
= window_
->bounds().size();
2719 return scoped_ptr
<ResizeLock
>(new CompositorResizeLock(
2722 defer_compositor_lock
,
2723 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs
)));
2726 void RenderWidgetHostViewAura::DelegatedFrameHostResizeLockWasReleased() {
2727 host_
->WasResized();
2730 void RenderWidgetHostViewAura::DelegatedFrameHostSendCompositorSwapAck(
2731 int output_surface_id
,
2732 const cc::CompositorFrameAck
& ack
) {
2733 host_
->Send(new ViewMsg_SwapCompositorFrameAck(host_
->GetRoutingID(),
2734 output_surface_id
, ack
));
2737 void RenderWidgetHostViewAura::DelegatedFrameHostSendReclaimCompositorResources(
2738 int output_surface_id
,
2739 const cc::CompositorFrameAck
& ack
) {
2740 host_
->Send(new ViewMsg_ReclaimCompositorResources(host_
->GetRoutingID(),
2741 output_surface_id
, ack
));
2744 void RenderWidgetHostViewAura::DelegatedFrameHostOnLostCompositorResources() {
2745 host_
->ScheduleComposite();
2748 void RenderWidgetHostViewAura::DelegatedFrameHostUpdateVSyncParameters(
2749 const base::TimeTicks
& timebase
,
2750 const base::TimeDelta
& interval
) {
2751 host_
->UpdateVSyncParameters(timebase
, interval
);
2754 void RenderWidgetHostViewAura::OnDidNavigateMainFrameToNewPage() {
2755 ui::GestureRecognizer::Get()->CancelActiveTouches(window_
);
2758 uint32_t RenderWidgetHostViewAura::GetSurfaceIdNamespace() {
2759 return delegated_frame_host_
->GetSurfaceIdNamespace();
2762 ////////////////////////////////////////////////////////////////////////////////
2763 // RenderWidgetHostViewBase, public:
2766 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo
* results
) {
2767 GetScreenInfoForWindow(results
, NULL
);
2770 } // namespace content