[blink-in-js] Migrate resources required for blink-in-js to grd - part 2
[chromium-blink-merge.git] / content / browser / renderer_host / render_widget_host_view_aura.cc
bloba54d860bc9e646cb9c5d0c9b52559e8042e2f17f
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"
7 #include "base/auto_reset.h"
8 #include "base/basictypes.h"
9 #include "base/bind.h"
10 #include "base/callback_helpers.h"
11 #include "base/command_line.h"
12 #include "base/debug/trace_event.h"
13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/string_number_conversions.h"
16 #include "cc/layers/layer.h"
17 #include "cc/output/copy_output_request.h"
18 #include "cc/output/copy_output_result.h"
19 #include "cc/resources/texture_mailbox.h"
20 #include "cc/trees/layer_tree_settings.h"
21 #include "content/browser/accessibility/browser_accessibility_manager.h"
22 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
23 #include "content/browser/frame_host/frame_tree.h"
24 #include "content/browser/frame_host/frame_tree_node.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h"
26 #include "content/browser/gpu/compositor_util.h"
27 #include "content/browser/renderer_host/compositor_resize_lock_aura.h"
28 #include "content/browser/renderer_host/dip_util.h"
29 #include "content/browser/renderer_host/input/synthetic_gesture_target_aura.h"
30 #include "content/browser/renderer_host/overscroll_controller.h"
31 #include "content/browser/renderer_host/render_view_host_delegate.h"
32 #include "content/browser/renderer_host/render_view_host_impl.h"
33 #include "content/browser/renderer_host/render_widget_host_impl.h"
34 #include "content/browser/renderer_host/ui_events_helper.h"
35 #include "content/browser/renderer_host/web_input_event_aura.h"
36 #include "content/common/gpu/client/gl_helper.h"
37 #include "content/common/gpu/gpu_messages.h"
38 #include "content/common/view_messages.h"
39 #include "content/public/browser/content_browser_client.h"
40 #include "content/public/browser/overscroll_configuration.h"
41 #include "content/public/browser/render_view_host.h"
42 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
43 #include "content/public/browser/user_metrics.h"
44 #include "content/public/common/content_switches.h"
45 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
46 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
47 #include "third_party/WebKit/public/web/WebInputEvent.h"
48 #include "ui/aura/client/aura_constants.h"
49 #include "ui/aura/client/cursor_client.h"
50 #include "ui/aura/client/cursor_client_observer.h"
51 #include "ui/aura/client/focus_client.h"
52 #include "ui/aura/client/screen_position_client.h"
53 #include "ui/aura/client/window_tree_client.h"
54 #include "ui/aura/env.h"
55 #include "ui/aura/window.h"
56 #include "ui/aura/window_event_dispatcher.h"
57 #include "ui/aura/window_observer.h"
58 #include "ui/aura/window_tracker.h"
59 #include "ui/aura/window_tree_host.h"
60 #include "ui/base/clipboard/scoped_clipboard_writer.h"
61 #include "ui/base/hit_test.h"
62 #include "ui/base/ime/input_method.h"
63 #include "ui/base/ui_base_types.h"
64 #include "ui/compositor/compositor_vsync_manager.h"
65 #include "ui/compositor/dip_util.h"
66 #include "ui/events/event.h"
67 #include "ui/events/event_utils.h"
68 #include "ui/events/gestures/gesture_recognizer.h"
69 #include "ui/gfx/canvas.h"
70 #include "ui/gfx/display.h"
71 #include "ui/gfx/rect_conversions.h"
72 #include "ui/gfx/screen.h"
73 #include "ui/gfx/size_conversions.h"
74 #include "ui/gfx/skia_util.h"
75 #include "ui/wm/public/activation_client.h"
76 #include "ui/wm/public/scoped_tooltip_disabler.h"
77 #include "ui/wm/public/tooltip_client.h"
78 #include "ui/wm/public/transient_window_client.h"
79 #include "ui/wm/public/window_types.h"
81 #if defined(OS_WIN)
82 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
83 #include "content/browser/accessibility/browser_accessibility_win.h"
84 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
85 #include "content/common/plugin_constants_win.h"
86 #include "ui/base/win/hidden_window.h"
87 #include "ui/gfx/gdi_util.h"
88 #include "ui/gfx/win/dpi.h"
89 #endif
91 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
92 #include "content/common/input_messages.h"
93 #include "ui/events/linux/text_edit_command_auralinux.h"
94 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
95 #endif
97 using gfx::RectToSkIRect;
98 using gfx::SkIRectToRect;
100 using blink::WebScreenInfo;
101 using blink::WebInputEvent;
102 using blink::WebGestureEvent;
103 using blink::WebTouchEvent;
105 namespace content {
107 namespace {
109 // In mouse lock mode, we need to prevent the (invisible) cursor from hitting
110 // the border of the view, in order to get valid movement information. However,
111 // forcing the cursor back to the center of the view after each mouse move
112 // doesn't work well. It reduces the frequency of useful mouse move messages
113 // significantly. Therefore, we move the cursor to the center of the view only
114 // if it approaches the border. |kMouseLockBorderPercentage| specifies the width
115 // of the border area, in percentage of the corresponding dimension.
116 const int kMouseLockBorderPercentage = 15;
118 // When accelerated compositing is enabled and a widget resize is pending,
119 // we delay further resizes of the UI. The following constant is the maximum
120 // length of time that we should delay further UI resizes while waiting for a
121 // resized frame from a renderer.
122 const int kResizeLockTimeoutMs = 67;
124 #if defined(OS_WIN)
125 // Used to associate a plugin HWND with its RenderWidgetHostViewAura instance.
126 const wchar_t kWidgetOwnerProperty[] = L"RenderWidgetHostViewAuraOwner";
128 BOOL CALLBACK WindowDestroyingCallback(HWND window, LPARAM param) {
129 RenderWidgetHostViewAura* widget =
130 reinterpret_cast<RenderWidgetHostViewAura*>(param);
131 if (GetProp(window, kWidgetOwnerProperty) == widget) {
132 // Properties set on HWNDs must be removed to avoid leaks.
133 RemoveProp(window, kWidgetOwnerProperty);
134 RenderWidgetHostViewBase::DetachPluginWindowsCallback(window);
136 return TRUE;
139 BOOL CALLBACK HideWindowsCallback(HWND window, LPARAM param) {
140 RenderWidgetHostViewAura* widget =
141 reinterpret_cast<RenderWidgetHostViewAura*>(param);
142 if (GetProp(window, kWidgetOwnerProperty) == widget)
143 SetParent(window, ui::GetHiddenWindow());
144 return TRUE;
147 BOOL CALLBACK ShowWindowsCallback(HWND window, LPARAM param) {
148 RenderWidgetHostViewAura* widget =
149 reinterpret_cast<RenderWidgetHostViewAura*>(param);
151 if (GetProp(window, kWidgetOwnerProperty) == widget &&
152 widget->GetNativeView()->GetHost()) {
153 HWND parent = widget->GetNativeView()->GetHost()->GetAcceleratedWidget();
154 SetParent(window, parent);
156 return TRUE;
159 struct CutoutRectsParams {
160 RenderWidgetHostViewAura* widget;
161 std::vector<gfx::Rect> cutout_rects;
162 std::map<HWND, WebPluginGeometry>* geometry;
165 // Used to update the region for the windowed plugin to draw in. We start with
166 // the clip rect from the renderer, then remove the cutout rects from the
167 // renderer, and then remove the transient windows from the root window and the
168 // constrained windows from the parent window.
169 BOOL CALLBACK SetCutoutRectsCallback(HWND window, LPARAM param) {
170 CutoutRectsParams* params = reinterpret_cast<CutoutRectsParams*>(param);
172 if (GetProp(window, kWidgetOwnerProperty) == params->widget) {
173 // First calculate the offset of this plugin from the root window, since
174 // the cutouts are relative to the root window.
175 HWND parent =
176 params->widget->GetNativeView()->GetHost()->GetAcceleratedWidget();
177 POINT offset;
178 offset.x = offset.y = 0;
179 MapWindowPoints(window, parent, &offset, 1);
181 // Now get the cached clip rect and cutouts for this plugin window that came
182 // from the renderer.
183 std::map<HWND, WebPluginGeometry>::iterator i = params->geometry->begin();
184 while (i != params->geometry->end() &&
185 i->second.window != window &&
186 GetParent(i->second.window) != window) {
187 ++i;
190 if (i == params->geometry->end()) {
191 NOTREACHED();
192 return TRUE;
195 HRGN hrgn = CreateRectRgn(i->second.clip_rect.x(),
196 i->second.clip_rect.y(),
197 i->second.clip_rect.right(),
198 i->second.clip_rect.bottom());
199 // We start with the cutout rects that came from the renderer, then add the
200 // ones that came from transient and constrained windows.
201 std::vector<gfx::Rect> cutout_rects = i->second.cutout_rects;
202 for (size_t i = 0; i < params->cutout_rects.size(); ++i) {
203 gfx::Rect offset_cutout = params->cutout_rects[i];
204 offset_cutout.Offset(-offset.x, -offset.y);
205 cutout_rects.push_back(offset_cutout);
207 gfx::SubtractRectanglesFromRegion(hrgn, cutout_rects);
208 // If we don't have any cutout rects then no point in messing with the
209 // window region.
210 if (cutout_rects.size())
211 SetWindowRgn(window, hrgn, TRUE);
213 return TRUE;
216 // A callback function for EnumThreadWindows to enumerate and dismiss
217 // any owned popup windows.
218 BOOL CALLBACK DismissOwnedPopups(HWND window, LPARAM arg) {
219 const HWND toplevel_hwnd = reinterpret_cast<HWND>(arg);
221 if (::IsWindowVisible(window)) {
222 const HWND owner = ::GetWindow(window, GW_OWNER);
223 if (toplevel_hwnd == owner) {
224 ::PostMessage(window, WM_CANCELMODE, 0, 0);
228 return TRUE;
230 #endif
232 void UpdateWebTouchEventAfterDispatch(blink::WebTouchEvent* event,
233 blink::WebTouchPoint* point) {
234 if (point->state != blink::WebTouchPoint::StateReleased &&
235 point->state != blink::WebTouchPoint::StateCancelled)
236 return;
238 const unsigned new_length = event->touchesLength - 1;
239 // Work around a gcc 4.9 bug. crbug.com/392872
240 if (new_length >= event->touchesLengthCap)
241 return;
243 for (unsigned i = point - event->touches; i < new_length; ++i)
244 event->touches[i] = event->touches[i + 1];
245 event->touchesLength = new_length;
248 bool CanRendererHandleEvent(const ui::MouseEvent* event) {
249 if (event->type() == ui::ET_MOUSE_CAPTURE_CHANGED)
250 return false;
252 #if defined(OS_WIN)
253 // Renderer cannot handle WM_XBUTTON or NC events.
254 switch (event->native_event().message) {
255 case WM_XBUTTONDOWN:
256 case WM_XBUTTONUP:
257 case WM_XBUTTONDBLCLK:
258 case WM_NCMOUSELEAVE:
259 case WM_NCMOUSEMOVE:
260 case WM_NCLBUTTONDOWN:
261 case WM_NCLBUTTONUP:
262 case WM_NCLBUTTONDBLCLK:
263 case WM_NCRBUTTONDOWN:
264 case WM_NCRBUTTONUP:
265 case WM_NCRBUTTONDBLCLK:
266 case WM_NCMBUTTONDOWN:
267 case WM_NCMBUTTONUP:
268 case WM_NCMBUTTONDBLCLK:
269 case WM_NCXBUTTONDOWN:
270 case WM_NCXBUTTONUP:
271 case WM_NCXBUTTONDBLCLK:
272 return false;
273 default:
274 break;
276 #elif defined(USE_X11)
277 // Renderer only supports standard mouse buttons, so ignore programmable
278 // buttons.
279 switch (event->type()) {
280 case ui::ET_MOUSE_PRESSED:
281 case ui::ET_MOUSE_RELEASED:
282 return event->IsAnyButton();
283 default:
284 break;
286 #endif
287 return true;
290 // We don't mark these as handled so that they're sent back to the
291 // DefWindowProc so it can generate WM_APPCOMMAND as necessary.
292 bool IsXButtonUpEvent(const ui::MouseEvent* event) {
293 #if defined(OS_WIN)
294 switch (event->native_event().message) {
295 case WM_XBUTTONUP:
296 case WM_NCXBUTTONUP:
297 return true;
299 #endif
300 return false;
303 void GetScreenInfoForWindow(WebScreenInfo* results, aura::Window* window) {
304 const gfx::Display display = window ?
305 gfx::Screen::GetScreenFor(window)->GetDisplayNearestWindow(window) :
306 gfx::Screen::GetScreenFor(window)->GetPrimaryDisplay();
307 results->rect = display.bounds();
308 results->availableRect = display.work_area();
309 // TODO(derat|oshima): Don't hardcode this. Get this from display object.
310 results->depth = 24;
311 results->depthPerComponent = 8;
312 results->deviceScaleFactor = display.device_scale_factor();
314 // The Display rotation and the WebScreenInfo orientation are not the same
315 // angle. The former is the physical display rotation while the later is the
316 // rotation required by the content to be shown properly on the screen, in
317 // other words, relative to the physical display.
318 results->orientationAngle = display.RotationAsDegree();
319 if (results->orientationAngle == 90)
320 results->orientationAngle = 270;
321 else if (results->orientationAngle == 270)
322 results->orientationAngle = 90;
324 results->orientationType =
325 RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display);
328 bool PointerEventActivates(const ui::Event& event) {
329 if (event.type() == ui::ET_MOUSE_PRESSED)
330 return true;
332 if (event.type() == ui::ET_GESTURE_BEGIN) {
333 const ui::GestureEvent& gesture =
334 static_cast<const ui::GestureEvent&>(event);
335 return gesture.details().touch_points() == 1;
338 return false;
341 } // namespace
343 // We need to watch for mouse events outside a Web Popup or its parent
344 // and dismiss the popup for certain events.
345 class RenderWidgetHostViewAura::EventFilterForPopupExit
346 : public ui::EventHandler {
347 public:
348 explicit EventFilterForPopupExit(RenderWidgetHostViewAura* rwhva)
349 : rwhva_(rwhva) {
350 DCHECK(rwhva_);
351 aura::Env::GetInstance()->AddPreTargetHandler(this);
354 virtual ~EventFilterForPopupExit() {
355 aura::Env::GetInstance()->RemovePreTargetHandler(this);
358 // Overridden from ui::EventHandler
359 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
360 rwhva_->ApplyEventFilterForPopupExit(event);
363 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
364 rwhva_->ApplyEventFilterForPopupExit(event);
367 private:
368 RenderWidgetHostViewAura* rwhva_;
370 DISALLOW_COPY_AND_ASSIGN(EventFilterForPopupExit);
373 void RenderWidgetHostViewAura::ApplyEventFilterForPopupExit(
374 ui::LocatedEvent* event) {
375 if (in_shutdown_ || is_fullscreen_ || !event->target())
376 return;
378 if (event->type() != ui::ET_MOUSE_PRESSED &&
379 event->type() != ui::ET_TOUCH_PRESSED) {
380 return;
383 aura::Window* target = static_cast<aura::Window*>(event->target());
384 if (target != window_ &&
385 (!popup_parent_host_view_ ||
386 target != popup_parent_host_view_->window_)) {
387 // Note: popup_parent_host_view_ may be NULL when there are multiple
388 // popup children per view. See: RenderWidgetHostViewAura::InitAsPopup().
389 in_shutdown_ = true;
390 host_->Shutdown();
394 // We have to implement the WindowObserver interface on a separate object
395 // because clang doesn't like implementing multiple interfaces that have
396 // methods with the same name. This object is owned by the
397 // RenderWidgetHostViewAura.
398 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver {
399 public:
400 explicit WindowObserver(RenderWidgetHostViewAura* view)
401 : view_(view) {
402 view_->window_->AddObserver(this);
405 virtual ~WindowObserver() {
406 view_->window_->RemoveObserver(this);
409 // Overridden from aura::WindowObserver:
410 virtual void OnWindowAddedToRootWindow(aura::Window* window) OVERRIDE {
411 if (window == view_->window_)
412 view_->AddedToRootWindow();
415 virtual void OnWindowRemovingFromRootWindow(aura::Window* window,
416 aura::Window* new_root) OVERRIDE {
417 if (window == view_->window_)
418 view_->RemovingFromRootWindow();
421 private:
422 RenderWidgetHostViewAura* view_;
424 DISALLOW_COPY_AND_ASSIGN(WindowObserver);
427 ////////////////////////////////////////////////////////////////////////////////
428 // RenderWidgetHostViewAura, public:
430 RenderWidgetHostViewAura::RenderWidgetHostViewAura(RenderWidgetHost* host)
431 : host_(RenderWidgetHostImpl::From(host)),
432 window_(new aura::Window(this)),
433 delegated_frame_host_(new DelegatedFrameHost(this)),
434 in_shutdown_(false),
435 in_bounds_changed_(false),
436 is_fullscreen_(false),
437 popup_parent_host_view_(NULL),
438 popup_child_host_view_(NULL),
439 is_loading_(false),
440 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
441 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
442 can_compose_inline_(true),
443 has_composition_text_(false),
444 accept_return_character_(false),
445 last_swapped_software_frame_scale_factor_(1.f),
446 paint_canvas_(NULL),
447 synthetic_move_sent_(false),
448 cursor_visibility_state_in_renderer_(UNKNOWN),
449 #if defined(OS_WIN)
450 legacy_render_widget_host_HWND_(NULL),
451 legacy_window_destroyed_(false),
452 #endif
453 has_snapped_to_boundary_(false),
454 touch_editing_client_(NULL),
455 weak_ptr_factory_(this) {
456 host_->SetView(this);
457 window_observer_.reset(new WindowObserver(this));
458 aura::client::SetTooltipText(window_, &tooltip_);
459 aura::client::SetActivationDelegate(window_, this);
460 aura::client::SetActivationChangeObserver(window_, this);
461 aura::client::SetFocusChangeObserver(window_, this);
462 window_->set_layer_owner_delegate(delegated_frame_host_.get());
463 gfx::Screen::GetScreenFor(window_)->AddObserver(this);
465 bool overscroll_enabled = base::CommandLine::ForCurrentProcess()->
466 GetSwitchValueASCII(switches::kOverscrollHistoryNavigation) != "0";
467 SetOverscrollControllerEnabled(overscroll_enabled);
470 ////////////////////////////////////////////////////////////////////////////////
471 // RenderWidgetHostViewAura, RenderWidgetHostView implementation:
473 void RenderWidgetHostViewAura::InitAsChild(
474 gfx::NativeView parent_view) {
475 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
476 window_->Init(aura::WINDOW_LAYER_TEXTURED);
477 window_->SetName("RenderWidgetHostViewAura");
480 void RenderWidgetHostViewAura::InitAsPopup(
481 RenderWidgetHostView* parent_host_view,
482 const gfx::Rect& bounds_in_screen) {
483 popup_parent_host_view_ =
484 static_cast<RenderWidgetHostViewAura*>(parent_host_view);
486 // TransientWindowClient may be NULL during tests.
487 aura::client::TransientWindowClient* transient_window_client =
488 aura::client::GetTransientWindowClient();
489 RenderWidgetHostViewAura* old_child =
490 popup_parent_host_view_->popup_child_host_view_;
491 if (old_child) {
492 // TODO(jhorwich): Allow multiple popup_child_host_view_ per view, or
493 // similar mechanism to ensure a second popup doesn't cause the first one
494 // to never get a chance to filter events. See crbug.com/160589.
495 DCHECK(old_child->popup_parent_host_view_ == popup_parent_host_view_);
496 if (transient_window_client) {
497 transient_window_client->RemoveTransientChild(
498 popup_parent_host_view_->window_, old_child->window_);
500 old_child->popup_parent_host_view_ = NULL;
502 popup_parent_host_view_->popup_child_host_view_ = this;
503 window_->SetType(ui::wm::WINDOW_TYPE_MENU);
504 window_->Init(aura::WINDOW_LAYER_TEXTURED);
505 window_->SetName("RenderWidgetHostViewAura");
507 aura::Window* root = popup_parent_host_view_->window_->GetRootWindow();
508 aura::client::ParentWindowWithContext(window_, root, bounds_in_screen);
509 // Setting the transient child allows for the popup to get mouse events when
510 // in a system modal dialog.
511 // This fixes crbug.com/328593.
512 if (transient_window_client) {
513 transient_window_client->AddTransientChild(
514 popup_parent_host_view_->window_, window_);
517 SetBounds(bounds_in_screen);
518 Show();
519 #if !defined(OS_WIN) && !defined(OS_CHROMEOS)
520 if (NeedsInputGrab())
521 window_->SetCapture();
522 #endif
524 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this));
527 void RenderWidgetHostViewAura::InitAsFullscreen(
528 RenderWidgetHostView* reference_host_view) {
529 is_fullscreen_ = true;
530 window_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
531 window_->Init(aura::WINDOW_LAYER_TEXTURED);
532 window_->SetName("RenderWidgetHostViewAura");
533 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
535 aura::Window* parent = NULL;
536 gfx::Rect bounds;
537 if (reference_host_view) {
538 aura::Window* reference_window =
539 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_;
540 if (reference_window) {
541 host_tracker_.reset(new aura::WindowTracker);
542 host_tracker_->Add(reference_window);
544 gfx::Display display = gfx::Screen::GetScreenFor(window_)->
545 GetDisplayNearestWindow(reference_window);
546 parent = reference_window->GetRootWindow();
547 bounds = display.bounds();
549 aura::client::ParentWindowWithContext(window_, parent, bounds);
550 Show();
551 Focus();
554 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const {
555 return host_;
558 void RenderWidgetHostViewAura::WasShown() {
559 DCHECK(host_);
560 if (!host_->is_hidden())
561 return;
563 bool has_saved_frame = delegated_frame_host_->HasSavedFrame();
564 ui::LatencyInfo renderer_latency_info, browser_latency_info;
565 if (has_saved_frame) {
566 browser_latency_info.AddLatencyNumber(
567 ui::TAB_SHOW_COMPONENT, host_->GetLatencyComponentId(), 0);
568 } else {
569 renderer_latency_info.AddLatencyNumber(
570 ui::TAB_SHOW_COMPONENT, host_->GetLatencyComponentId(), 0);
572 host_->WasShown(renderer_latency_info);
574 aura::Window* root = window_->GetRootWindow();
575 if (root) {
576 aura::client::CursorClient* cursor_client =
577 aura::client::GetCursorClient(root);
578 if (cursor_client)
579 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible());
582 delegated_frame_host_->WasShown(browser_latency_info);
584 #if defined(OS_WIN)
585 if (legacy_render_widget_host_HWND_) {
586 // Reparent the legacy Chrome_RenderWidgetHostHWND window to the parent
587 // window before reparenting any plugins. This ensures that the plugin
588 // windows stay on top of the child Zorder in the parent and receive
589 // mouse events, etc.
590 legacy_render_widget_host_HWND_->UpdateParent(
591 GetNativeView()->GetHost()->GetAcceleratedWidget());
592 legacy_render_widget_host_HWND_->SetBounds(
593 window_->GetBoundsInRootWindow());
595 LPARAM lparam = reinterpret_cast<LPARAM>(this);
596 EnumChildWindows(ui::GetHiddenWindow(), ShowWindowsCallback, lparam);
597 #endif
600 void RenderWidgetHostViewAura::WasHidden() {
601 if (!host_ || host_->is_hidden())
602 return;
603 host_->WasHidden();
604 delegated_frame_host_->WasHidden();
606 #if defined(OS_WIN)
607 constrained_rects_.clear();
608 aura::WindowTreeHost* host = window_->GetHost();
609 if (host) {
610 HWND parent = host->GetAcceleratedWidget();
611 LPARAM lparam = reinterpret_cast<LPARAM>(this);
612 EnumChildWindows(parent, HideWindowsCallback, lparam);
613 // We reparent the legacy Chrome_RenderWidgetHostHWND window to the global
614 // hidden window on the same lines as Windowed plugin windows.
615 if (legacy_render_widget_host_HWND_)
616 legacy_render_widget_host_HWND_->UpdateParent(ui::GetHiddenWindow());
618 #endif
621 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) {
622 // For a SetSize operation, we don't care what coordinate system the origin
623 // of the window is in, it's only important to make sure that the origin
624 // remains constant after the operation.
625 InternalSetBounds(gfx::Rect(window_->bounds().origin(), size));
628 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) {
629 gfx::Point relative_origin(rect.origin());
631 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but
632 // Window::SetBounds() takes parent coordinates, so do the conversion here.
633 aura::Window* root = window_->GetRootWindow();
634 if (root) {
635 aura::client::ScreenPositionClient* screen_position_client =
636 aura::client::GetScreenPositionClient(root);
637 if (screen_position_client) {
638 screen_position_client->ConvertPointFromScreen(
639 window_->parent(), &relative_origin);
643 InternalSetBounds(gfx::Rect(relative_origin, rect.size()));
646 gfx::Vector2dF RenderWidgetHostViewAura::GetLastScrollOffset() const {
647 return last_scroll_offset_;
650 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const {
651 return window_;
654 gfx::NativeViewId RenderWidgetHostViewAura::GetNativeViewId() const {
655 #if defined(OS_WIN)
656 aura::WindowTreeHost* host = window_->GetHost();
657 if (host)
658 return reinterpret_cast<gfx::NativeViewId>(host->GetAcceleratedWidget());
659 #endif
660 return static_cast<gfx::NativeViewId>(NULL);
663 gfx::NativeViewAccessible RenderWidgetHostViewAura::GetNativeViewAccessible() {
664 #if defined(OS_WIN)
665 aura::WindowTreeHost* host = window_->GetHost();
666 if (!host)
667 return static_cast<gfx::NativeViewAccessible>(NULL);
668 HWND hwnd = host->GetAcceleratedWidget();
669 BrowserAccessibilityManager* manager =
670 host_->GetOrCreateRootBrowserAccessibilityManager();
671 if (manager)
672 return manager->GetRoot()->ToBrowserAccessibilityWin();
673 #endif
675 NOTIMPLEMENTED();
676 return static_cast<gfx::NativeViewAccessible>(NULL);
679 ui::TextInputClient* RenderWidgetHostViewAura::GetTextInputClient() {
680 return this;
683 void RenderWidgetHostViewAura::SetKeyboardFocus() {
684 #if defined(OS_WIN)
685 if (CanFocus()) {
686 aura::WindowTreeHost* host = window_->GetHost();
687 if (host)
688 ::SetFocus(host->GetAcceleratedWidget());
690 #endif
693 RenderFrameHostImpl* RenderWidgetHostViewAura::GetFocusedFrame() {
694 if (!host_->IsRenderView())
695 return NULL;
696 RenderViewHost* rvh = RenderViewHost::From(host_);
697 FrameTreeNode* focused_frame =
698 rvh->GetDelegate()->GetFrameTree()->GetFocusedFrame();
699 if (!focused_frame)
700 return NULL;
702 return focused_frame->current_frame_host();
705 void RenderWidgetHostViewAura::MovePluginWindows(
706 const std::vector<WebPluginGeometry>& plugin_window_moves) {
707 #if defined(OS_WIN)
708 // We need to clip the rectangle to the tab's viewport, otherwise we will draw
709 // over the browser UI.
710 if (!window_->GetRootWindow()) {
711 DCHECK(plugin_window_moves.empty());
712 return;
714 HWND parent = window_->GetHost()->GetAcceleratedWidget();
715 gfx::Rect view_bounds = window_->GetBoundsInRootWindow();
716 std::vector<WebPluginGeometry> moves = plugin_window_moves;
718 gfx::Rect view_port(view_bounds.size());
720 for (size_t i = 0; i < moves.size(); ++i) {
721 gfx::Rect clip(moves[i].clip_rect);
722 gfx::Vector2d view_port_offset(
723 moves[i].window_rect.OffsetFromOrigin());
724 clip.Offset(view_port_offset);
725 clip.Intersect(view_port);
726 clip.Offset(-view_port_offset);
727 moves[i].clip_rect = clip;
729 moves[i].window_rect.Offset(view_bounds.OffsetFromOrigin());
731 plugin_window_moves_[moves[i].window] = moves[i];
733 // constrained_rects_ are relative to the root window. We want to convert
734 // them to be relative to the plugin window.
735 for (size_t j = 0; j < constrained_rects_.size(); ++j) {
736 gfx::Rect offset_cutout = constrained_rects_[j];
737 offset_cutout -= moves[i].window_rect.OffsetFromOrigin();
738 moves[i].cutout_rects.push_back(offset_cutout);
742 MovePluginWindowsHelper(parent, moves);
744 // Make sure each plugin window (or its wrapper if it exists) has a pointer to
745 // |this|.
746 for (size_t i = 0; i < moves.size(); ++i) {
747 HWND window = moves[i].window;
748 if (GetParent(window) != parent) {
749 window = GetParent(window);
751 if (!GetProp(window, kWidgetOwnerProperty))
752 SetProp(window, kWidgetOwnerProperty, this);
754 #endif // defined(OS_WIN)
757 void RenderWidgetHostViewAura::Focus() {
758 // Make sure we have a FocusClient before attempting to Focus(). In some
759 // situations we may not yet be in a valid Window hierarchy (such as reloading
760 // after out of memory discarded the tab).
761 aura::client::FocusClient* client = aura::client::GetFocusClient(window_);
762 if (client)
763 window_->Focus();
766 void RenderWidgetHostViewAura::Blur() {
767 window_->Blur();
770 bool RenderWidgetHostViewAura::HasFocus() const {
771 return window_->HasFocus();
774 bool RenderWidgetHostViewAura::IsSurfaceAvailableForCopy() const {
775 return delegated_frame_host_->CanCopyToBitmap();
778 void RenderWidgetHostViewAura::Show() {
779 window_->Show();
780 WasShown();
781 #if defined(OS_WIN)
782 if (legacy_render_widget_host_HWND_)
783 legacy_render_widget_host_HWND_->Show();
784 #endif
787 void RenderWidgetHostViewAura::Hide() {
788 window_->Hide();
789 WasHidden();
790 #if defined(OS_WIN)
791 if (legacy_render_widget_host_HWND_)
792 legacy_render_widget_host_HWND_->Hide();
793 #endif
796 bool RenderWidgetHostViewAura::IsShowing() {
797 return window_->IsVisible();
800 gfx::Rect RenderWidgetHostViewAura::GetViewBounds() const {
801 return window_->GetBoundsInScreen();
804 void RenderWidgetHostViewAura::SetBackgroundOpaque(bool opaque) {
805 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque);
806 host_->SetBackgroundOpaque(opaque);
807 window_->layer()->SetFillsBoundsOpaquely(opaque);
810 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() const {
811 gfx::Rect requested_rect(GetRequestedRendererSize());
812 requested_rect.Inset(insets_);
813 return requested_rect.size();
816 void RenderWidgetHostViewAura::SetInsets(const gfx::Insets& insets) {
817 if (insets != insets_) {
818 insets_ = insets;
819 host_->WasResized();
823 void RenderWidgetHostViewAura::UpdateCursor(const WebCursor& cursor) {
824 current_cursor_ = cursor;
825 const gfx::Display display = gfx::Screen::GetScreenFor(window_)->
826 GetDisplayNearestWindow(window_);
827 current_cursor_.SetDisplayInfo(display);
828 UpdateCursorIfOverSelf();
831 void RenderWidgetHostViewAura::SetIsLoading(bool is_loading) {
832 is_loading_ = is_loading;
833 UpdateCursorIfOverSelf();
836 void RenderWidgetHostViewAura::TextInputStateChanged(
837 const ViewHostMsg_TextInputState_Params& params) {
838 if (text_input_type_ != params.type ||
839 text_input_mode_ != params.mode ||
840 can_compose_inline_ != params.can_compose_inline) {
841 text_input_type_ = params.type;
842 text_input_mode_ = params.mode;
843 can_compose_inline_ = params.can_compose_inline;
844 if (GetInputMethod())
845 GetInputMethod()->OnTextInputTypeChanged(this);
846 if (touch_editing_client_)
847 touch_editing_client_->OnTextInputTypeChanged(text_input_type_);
849 if (params.show_ime_if_needed && params.type != ui::TEXT_INPUT_TYPE_NONE) {
850 if (GetInputMethod())
851 GetInputMethod()->ShowImeIfNeeded();
855 void RenderWidgetHostViewAura::ImeCancelComposition() {
856 if (GetInputMethod())
857 GetInputMethod()->CancelComposition(this);
858 has_composition_text_ = false;
861 void RenderWidgetHostViewAura::ImeCompositionRangeChanged(
862 const gfx::Range& range,
863 const std::vector<gfx::Rect>& character_bounds) {
864 composition_character_bounds_ = character_bounds;
867 void RenderWidgetHostViewAura::RenderProcessGone(base::TerminationStatus status,
868 int error_code) {
869 UpdateCursorIfOverSelf();
870 Destroy();
873 void RenderWidgetHostViewAura::Destroy() {
874 // Beware, this function is not called on all destruction paths. It will
875 // implicitly end up calling ~RenderWidgetHostViewAura though, so all
876 // destruction/cleanup code should happen there, not here.
877 in_shutdown_ = true;
878 delete window_;
881 void RenderWidgetHostViewAura::SetTooltipText(
882 const base::string16& tooltip_text) {
883 tooltip_ = tooltip_text;
884 aura::Window* root_window = window_->GetRootWindow();
885 aura::client::TooltipClient* tooltip_client =
886 aura::client::GetTooltipClient(root_window);
887 if (tooltip_client) {
888 tooltip_client->UpdateTooltip(window_);
889 // Content tooltips should be visible indefinitely.
890 tooltip_client->SetTooltipShownTimeout(window_, 0);
894 void RenderWidgetHostViewAura::SelectionChanged(const base::string16& text,
895 size_t offset,
896 const gfx::Range& range) {
897 RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
899 #if defined(USE_X11) && !defined(OS_CHROMEOS)
900 if (text.empty() || range.is_empty())
901 return;
902 size_t pos = range.GetMin() - offset;
903 size_t n = range.length();
905 DCHECK(pos + n <= text.length()) << "The text can not fully cover range.";
906 if (pos >= text.length()) {
907 NOTREACHED() << "The text can not cover range.";
908 return;
911 // Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
912 ui::ScopedClipboardWriter clipboard_writer(
913 ui::Clipboard::GetForCurrentThread(),
914 ui::CLIPBOARD_TYPE_SELECTION);
915 clipboard_writer.WriteText(text.substr(pos, n));
916 #endif // defined(USE_X11) && !defined(OS_CHROMEOS)
919 gfx::Size RenderWidgetHostViewAura::GetRequestedRendererSize() const {
920 return delegated_frame_host_->GetRequestedRendererSize();
923 void RenderWidgetHostViewAura::SelectionBoundsChanged(
924 const ViewHostMsg_SelectionBounds_Params& params) {
925 if (selection_anchor_rect_ == params.anchor_rect &&
926 selection_focus_rect_ == params.focus_rect)
927 return;
929 selection_anchor_rect_ = params.anchor_rect;
930 selection_focus_rect_ = params.focus_rect;
932 if (GetInputMethod())
933 GetInputMethod()->OnCaretBoundsChanged(this);
935 if (touch_editing_client_) {
936 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_,
937 selection_focus_rect_);
941 void RenderWidgetHostViewAura::CopyFromCompositingSurface(
942 const gfx::Rect& src_subrect,
943 const gfx::Size& dst_size,
944 const base::Callback<void(bool, const SkBitmap&)>& callback,
945 const SkColorType color_type) {
946 delegated_frame_host_->CopyFromCompositingSurface(
947 src_subrect, dst_size, callback, color_type);
950 void RenderWidgetHostViewAura::CopyFromCompositingSurfaceToVideoFrame(
951 const gfx::Rect& src_subrect,
952 const scoped_refptr<media::VideoFrame>& target,
953 const base::Callback<void(bool)>& callback) {
954 delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame(
955 src_subrect, target, callback);
958 bool RenderWidgetHostViewAura::CanCopyToVideoFrame() const {
959 return delegated_frame_host_->CanCopyToVideoFrame();
962 bool RenderWidgetHostViewAura::CanSubscribeFrame() const {
963 return delegated_frame_host_->CanSubscribeFrame();
966 void RenderWidgetHostViewAura::BeginFrameSubscription(
967 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) {
968 delegated_frame_host_->BeginFrameSubscription(subscriber.Pass());
971 void RenderWidgetHostViewAura::EndFrameSubscription() {
972 delegated_frame_host_->EndFrameSubscription();
975 void RenderWidgetHostViewAura::AcceleratedSurfaceInitialized(int host_id,
976 int route_id) {
979 #if defined(OS_WIN)
980 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const {
981 return (legacy_render_widget_host_HWND_ != NULL);
984 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects(
985 const std::vector<gfx::Rect>& rects) {
986 // Check this before setting constrained_rects_, so that next time they're set
987 // and we have a root window we don't early return.
988 if (!window_->GetHost())
989 return;
991 if (rects == constrained_rects_)
992 return;
994 constrained_rects_ = rects;
996 HWND parent = window_->GetHost()->GetAcceleratedWidget();
997 CutoutRectsParams params;
998 params.widget = this;
999 params.cutout_rects = constrained_rects_;
1000 params.geometry = &plugin_window_moves_;
1001 LPARAM lparam = reinterpret_cast<LPARAM>(&params);
1002 EnumChildWindows(parent, SetCutoutRectsCallback, lparam);
1005 void RenderWidgetHostViewAura::UpdateMouseLockRegion() {
1006 // Clip the cursor if chrome is running on regular desktop.
1007 if (gfx::Screen::GetScreenFor(window_) == gfx::Screen::GetNativeScreen()) {
1008 RECT window_rect = window_->GetBoundsInScreen().ToRECT();
1009 ::ClipCursor(&window_rect);
1013 void RenderWidgetHostViewAura::OnLegacyWindowDestroyed() {
1014 legacy_render_widget_host_HWND_ = NULL;
1015 legacy_window_destroyed_ = true;
1017 #endif
1019 void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped(
1020 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params_in_pixel,
1021 int gpu_host_id) {
1022 // Oldschool composited mode is no longer supported.
1025 void RenderWidgetHostViewAura::OnSwapCompositorFrame(
1026 uint32 output_surface_id,
1027 scoped_ptr<cc::CompositorFrame> frame) {
1028 TRACE_EVENT0("content", "RenderWidgetHostViewAura::OnSwapCompositorFrame");
1030 last_scroll_offset_ = frame->metadata.root_scroll_offset;
1031 if (frame->delegated_frame_data) {
1032 delegated_frame_host_->SwapDelegatedFrame(
1033 output_surface_id,
1034 frame->delegated_frame_data.Pass(),
1035 frame->metadata.device_scale_factor,
1036 frame->metadata.latency_info);
1037 return;
1040 if (frame->software_frame_data) {
1041 DLOG(ERROR) << "Unable to use software frame in aura";
1042 RecordAction(
1043 base::UserMetricsAction("BadMessageTerminate_SharedMemoryAura"));
1044 host_->GetProcess()->ReceivedBadMessage();
1045 return;
1049 #if defined(OS_WIN)
1050 void RenderWidgetHostViewAura::SetParentNativeViewAccessible(
1051 gfx::NativeViewAccessible accessible_parent) {
1054 gfx::NativeViewId RenderWidgetHostViewAura::GetParentForWindowlessPlugin()
1055 const {
1056 if (legacy_render_widget_host_HWND_) {
1057 return reinterpret_cast<gfx::NativeViewId>(
1058 legacy_render_widget_host_HWND_->hwnd());
1060 return NULL;
1062 #endif
1064 void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer(
1065 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params_in_pixel,
1066 int gpu_host_id) {
1067 // Oldschool composited mode is no longer supported.
1070 void RenderWidgetHostViewAura::AcceleratedSurfaceSuspend() {
1073 void RenderWidgetHostViewAura::AcceleratedSurfaceRelease() {
1076 bool RenderWidgetHostViewAura::HasAcceleratedSurface(
1077 const gfx::Size& desired_size) {
1078 // Aura doesn't use GetBackingStore for accelerated pages, so it doesn't
1079 // matter what is returned here as GetBackingStore is the only caller of this
1080 // method. TODO(jbates) implement this if other Aura code needs it.
1081 return false;
1084 void RenderWidgetHostViewAura::GetScreenInfo(WebScreenInfo* results) {
1085 GetScreenInfoForWindow(results, window_->GetRootWindow() ? window_ : NULL);
1088 gfx::Rect RenderWidgetHostViewAura::GetBoundsInRootWindow() {
1089 aura::Window* top_level = window_->GetToplevelWindow();
1090 gfx::Rect bounds(top_level->GetBoundsInScreen());
1092 #if defined(OS_WIN)
1093 // TODO(zturner,iyengar): This will break when we remove support for NPAPI and
1094 // remove the legacy hwnd, so a better fix will need to be decided when that
1095 // happens.
1096 if (UsesNativeWindowFrame()) {
1097 // aura::Window doesn't take into account non-client area of native windows
1098 // (e.g. HWNDs), so for that case ask Windows directly what the bounds are.
1099 aura::WindowTreeHost* host = top_level->GetHost();
1100 if (!host)
1101 return top_level->GetBoundsInScreen();
1102 RECT window_rect = {0};
1103 HWND hwnd = host->GetAcceleratedWidget();
1104 ::GetWindowRect(hwnd, &window_rect);
1105 bounds = gfx::Rect(window_rect);
1107 // Maximized windows are outdented from the work area by the frame thickness
1108 // even though this "frame" is not painted. This confuses code (and people)
1109 // that think of a maximized window as corresponding exactly to the work
1110 // area. Correct for this by subtracting the frame thickness back off.
1111 if (::IsZoomed(hwnd)) {
1112 bounds.Inset(GetSystemMetrics(SM_CXSIZEFRAME),
1113 GetSystemMetrics(SM_CYSIZEFRAME));
1115 bounds.Inset(GetSystemMetrics(SM_CXPADDEDBORDER),
1116 GetSystemMetrics(SM_CXPADDEDBORDER));
1120 bounds = gfx::win::ScreenToDIPRect(bounds);
1121 #endif
1123 return bounds;
1126 void RenderWidgetHostViewAura::WheelEventAck(
1127 const blink::WebMouseWheelEvent& event,
1128 InputEventAckState ack_result) {
1129 if (overscroll_controller_) {
1130 overscroll_controller_->ReceivedEventACK(
1131 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
1135 void RenderWidgetHostViewAura::GestureEventAck(
1136 const blink::WebGestureEvent& event,
1137 InputEventAckState ack_result) {
1138 if (touch_editing_client_)
1139 touch_editing_client_->GestureEventAck(event.type);
1141 if (overscroll_controller_) {
1142 overscroll_controller_->ReceivedEventACK(
1143 event, (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result));
1147 void RenderWidgetHostViewAura::ProcessAckedTouchEvent(
1148 const TouchEventWithLatencyInfo& touch, InputEventAckState ack_result) {
1149 ScopedVector<ui::TouchEvent> events;
1150 if (!MakeUITouchEventsFromWebTouchEvents(touch, &events,
1151 SCREEN_COORDINATES))
1152 return;
1154 aura::WindowTreeHost* host = window_->GetHost();
1155 // |host| is NULL during tests.
1156 if (!host)
1157 return;
1159 ui::EventResult result = (ack_result ==
1160 INPUT_EVENT_ACK_STATE_CONSUMED) ? ui::ER_HANDLED : ui::ER_UNHANDLED;
1161 for (ScopedVector<ui::TouchEvent>::iterator iter = events.begin(),
1162 end = events.end(); iter != end; ++iter) {
1163 host->dispatcher()->ProcessedTouchEvent((*iter), window_, result);
1167 scoped_ptr<SyntheticGestureTarget>
1168 RenderWidgetHostViewAura::CreateSyntheticGestureTarget() {
1169 return scoped_ptr<SyntheticGestureTarget>(
1170 new SyntheticGestureTargetAura(host_));
1173 InputEventAckState RenderWidgetHostViewAura::FilterInputEvent(
1174 const blink::WebInputEvent& input_event) {
1175 bool consumed = false;
1176 if (input_event.type == WebInputEvent::GestureFlingStart) {
1177 const WebGestureEvent& gesture_event =
1178 static_cast<const WebGestureEvent&>(input_event);
1179 // Zero-velocity touchpad flings are an Aura-specific signal that the
1180 // touchpad scroll has ended, and should not be forwarded to the renderer.
1181 if (gesture_event.sourceDevice == blink::WebGestureDeviceTouchpad &&
1182 !gesture_event.data.flingStart.velocityX &&
1183 !gesture_event.data.flingStart.velocityY) {
1184 consumed = true;
1188 if (overscroll_controller_)
1189 consumed |= overscroll_controller_->WillHandleEvent(input_event);
1191 return consumed && !WebTouchEvent::isTouchEventType(input_event.type)
1192 ? INPUT_EVENT_ACK_STATE_CONSUMED
1193 : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1196 BrowserAccessibilityManager*
1197 RenderWidgetHostViewAura::CreateBrowserAccessibilityManager(
1198 BrowserAccessibilityDelegate* delegate) {
1199 BrowserAccessibilityManager* manager = NULL;
1200 #if defined(OS_WIN)
1201 manager = new BrowserAccessibilityManagerWin(
1202 BrowserAccessibilityManagerWin::GetEmptyDocument(), delegate);
1203 #else
1204 manager = BrowserAccessibilityManager::Create(
1205 BrowserAccessibilityManager::GetEmptyDocument(), delegate);
1206 #endif
1207 return manager;
1210 gfx::AcceleratedWidget
1211 RenderWidgetHostViewAura::AccessibilityGetAcceleratedWidget() {
1212 #if defined(OS_WIN)
1213 if (legacy_render_widget_host_HWND_)
1214 return legacy_render_widget_host_HWND_->hwnd();
1215 #endif
1216 return gfx::kNullAcceleratedWidget;
1219 gfx::NativeViewAccessible
1220 RenderWidgetHostViewAura::AccessibilityGetNativeViewAccessible() {
1221 #if defined(OS_WIN)
1222 if (legacy_render_widget_host_HWND_)
1223 return legacy_render_widget_host_HWND_->window_accessible();
1224 #endif
1225 return NULL;
1229 gfx::GLSurfaceHandle RenderWidgetHostViewAura::GetCompositingSurface() {
1230 return ImageTransportFactory::GetInstance()->GetSharedSurfaceHandle();
1233 bool RenderWidgetHostViewAura::LockMouse() {
1234 aura::Window* root_window = window_->GetRootWindow();
1235 if (!root_window)
1236 return false;
1238 if (mouse_locked_)
1239 return true;
1241 mouse_locked_ = true;
1242 #if !defined(OS_WIN)
1243 window_->SetCapture();
1244 #else
1245 UpdateMouseLockRegion();
1246 #endif
1247 aura::client::CursorClient* cursor_client =
1248 aura::client::GetCursorClient(root_window);
1249 if (cursor_client) {
1250 cursor_client->HideCursor();
1251 cursor_client->LockCursor();
1254 if (ShouldMoveToCenter()) {
1255 synthetic_move_sent_ = true;
1256 window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint());
1258 tooltip_disabler_.reset(new aura::client::ScopedTooltipDisabler(root_window));
1259 return true;
1262 void RenderWidgetHostViewAura::UnlockMouse() {
1263 tooltip_disabler_.reset();
1265 aura::Window* root_window = window_->GetRootWindow();
1266 if (!mouse_locked_ || !root_window)
1267 return;
1269 mouse_locked_ = false;
1271 #if !defined(OS_WIN)
1272 window_->ReleaseCapture();
1273 #else
1274 ::ClipCursor(NULL);
1275 #endif
1276 window_->MoveCursorTo(unlocked_mouse_position_);
1277 aura::client::CursorClient* cursor_client =
1278 aura::client::GetCursorClient(root_window);
1279 if (cursor_client) {
1280 cursor_client->UnlockCursor();
1281 cursor_client->ShowCursor();
1284 host_->LostMouseLock();
1287 ////////////////////////////////////////////////////////////////////////////////
1288 // RenderWidgetHostViewAura, ui::TextInputClient implementation:
1289 void RenderWidgetHostViewAura::SetCompositionText(
1290 const ui::CompositionText& composition) {
1291 if (!host_)
1292 return;
1294 // TODO(suzhe): convert both renderer_host and renderer to use
1295 // ui::CompositionText.
1296 std::vector<blink::WebCompositionUnderline> underlines;
1297 underlines.reserve(composition.underlines.size());
1298 for (std::vector<ui::CompositionUnderline>::const_iterator it =
1299 composition.underlines.begin();
1300 it != composition.underlines.end(); ++it) {
1301 underlines.push_back(
1302 blink::WebCompositionUnderline(static_cast<unsigned>(it->start_offset),
1303 static_cast<unsigned>(it->end_offset),
1304 it->color,
1305 it->thick,
1306 it->background_color));
1309 // TODO(suzhe): due to a bug of webkit, we can't use selection range with
1310 // composition string. See: https://bugs.webkit.org/show_bug.cgi?id=37788
1311 host_->ImeSetComposition(composition.text, underlines,
1312 composition.selection.end(),
1313 composition.selection.end());
1315 has_composition_text_ = !composition.text.empty();
1318 void RenderWidgetHostViewAura::ConfirmCompositionText() {
1319 if (host_ && has_composition_text_) {
1320 host_->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
1321 false);
1323 has_composition_text_ = false;
1326 void RenderWidgetHostViewAura::ClearCompositionText() {
1327 if (host_ && has_composition_text_)
1328 host_->ImeCancelComposition();
1329 has_composition_text_ = false;
1332 void RenderWidgetHostViewAura::InsertText(const base::string16& text) {
1333 DCHECK(text_input_type_ != ui::TEXT_INPUT_TYPE_NONE);
1334 if (host_)
1335 host_->ImeConfirmComposition(text, gfx::Range::InvalidRange(), false);
1336 has_composition_text_ = false;
1339 void RenderWidgetHostViewAura::InsertChar(base::char16 ch, int flags) {
1340 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1341 popup_child_host_view_->InsertChar(ch, flags);
1342 return;
1345 // Ignore character messages for VKEY_RETURN sent on CTRL+M. crbug.com/315547
1346 if (host_ && (accept_return_character_ || ch != ui::VKEY_RETURN)) {
1347 double now = ui::EventTimeForNow().InSecondsF();
1348 // Send a blink::WebInputEvent::Char event to |host_|.
1349 NativeWebKeyboardEvent webkit_event(ui::ET_KEY_PRESSED,
1350 true /* is_char */,
1352 flags,
1353 now);
1354 ForwardKeyboardEvent(webkit_event);
1358 gfx::NativeWindow RenderWidgetHostViewAura::GetAttachedWindow() const {
1359 return window_;
1362 ui::TextInputType RenderWidgetHostViewAura::GetTextInputType() const {
1363 return text_input_type_;
1366 ui::TextInputMode RenderWidgetHostViewAura::GetTextInputMode() const {
1367 return text_input_mode_;
1370 bool RenderWidgetHostViewAura::CanComposeInline() const {
1371 return can_compose_inline_;
1374 gfx::Rect RenderWidgetHostViewAura::ConvertRectToScreen(
1375 const gfx::Rect& rect) const {
1376 gfx::Point origin = rect.origin();
1377 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
1379 aura::Window* root_window = window_->GetRootWindow();
1380 if (!root_window)
1381 return rect;
1382 aura::client::ScreenPositionClient* screen_position_client =
1383 aura::client::GetScreenPositionClient(root_window);
1384 if (!screen_position_client)
1385 return rect;
1386 screen_position_client->ConvertPointToScreen(window_, &origin);
1387 screen_position_client->ConvertPointToScreen(window_, &end);
1388 return gfx::Rect(origin.x(),
1389 origin.y(),
1390 end.x() - origin.x(),
1391 end.y() - origin.y());
1394 gfx::Rect RenderWidgetHostViewAura::ConvertRectFromScreen(
1395 const gfx::Rect& rect) const {
1396 gfx::Point origin = rect.origin();
1397 gfx::Point end = gfx::Point(rect.right(), rect.bottom());
1399 aura::Window* root_window = window_->GetRootWindow();
1400 if (root_window) {
1401 aura::client::ScreenPositionClient* screen_position_client =
1402 aura::client::GetScreenPositionClient(root_window);
1403 screen_position_client->ConvertPointFromScreen(window_, &origin);
1404 screen_position_client->ConvertPointFromScreen(window_, &end);
1405 return gfx::Rect(origin.x(),
1406 origin.y(),
1407 end.x() - origin.x(),
1408 end.y() - origin.y());
1411 return rect;
1414 gfx::Rect RenderWidgetHostViewAura::GetCaretBounds() const {
1415 const gfx::Rect rect =
1416 gfx::UnionRects(selection_anchor_rect_, selection_focus_rect_);
1417 return ConvertRectToScreen(rect);
1420 bool RenderWidgetHostViewAura::GetCompositionCharacterBounds(
1421 uint32 index,
1422 gfx::Rect* rect) const {
1423 DCHECK(rect);
1424 if (index >= composition_character_bounds_.size())
1425 return false;
1426 *rect = ConvertRectToScreen(composition_character_bounds_[index]);
1427 return true;
1430 bool RenderWidgetHostViewAura::HasCompositionText() const {
1431 return has_composition_text_;
1434 bool RenderWidgetHostViewAura::GetTextRange(gfx::Range* range) const {
1435 range->set_start(selection_text_offset_);
1436 range->set_end(selection_text_offset_ + selection_text_.length());
1437 return true;
1440 bool RenderWidgetHostViewAura::GetCompositionTextRange(
1441 gfx::Range* range) const {
1442 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1443 NOTIMPLEMENTED();
1444 return false;
1447 bool RenderWidgetHostViewAura::GetSelectionRange(gfx::Range* range) const {
1448 range->set_start(selection_range_.start());
1449 range->set_end(selection_range_.end());
1450 return true;
1453 bool RenderWidgetHostViewAura::SetSelectionRange(const gfx::Range& range) {
1454 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1455 NOTIMPLEMENTED();
1456 return false;
1459 bool RenderWidgetHostViewAura::DeleteRange(const gfx::Range& range) {
1460 // TODO(suzhe): implement this method when fixing http://crbug.com/55130.
1461 NOTIMPLEMENTED();
1462 return false;
1465 bool RenderWidgetHostViewAura::GetTextFromRange(
1466 const gfx::Range& range,
1467 base::string16* text) const {
1468 gfx::Range selection_text_range(selection_text_offset_,
1469 selection_text_offset_ + selection_text_.length());
1471 if (!selection_text_range.Contains(range)) {
1472 text->clear();
1473 return false;
1475 if (selection_text_range.EqualsIgnoringDirection(range)) {
1476 // Avoid calling substr whose performance is low.
1477 *text = selection_text_;
1478 } else {
1479 *text = selection_text_.substr(
1480 range.GetMin() - selection_text_offset_,
1481 range.length());
1483 return true;
1486 void RenderWidgetHostViewAura::OnInputMethodChanged() {
1487 if (!host_)
1488 return;
1490 if (GetInputMethod())
1491 host_->SetInputMethodActive(GetInputMethod()->IsActive());
1493 // TODO(suzhe): implement the newly added “locale” property of HTML DOM
1494 // TextEvent.
1497 bool RenderWidgetHostViewAura::ChangeTextDirectionAndLayoutAlignment(
1498 base::i18n::TextDirection direction) {
1499 if (!host_)
1500 return false;
1501 host_->UpdateTextDirection(
1502 direction == base::i18n::RIGHT_TO_LEFT ?
1503 blink::WebTextDirectionRightToLeft :
1504 blink::WebTextDirectionLeftToRight);
1505 host_->NotifyTextDirection();
1506 return true;
1509 void RenderWidgetHostViewAura::ExtendSelectionAndDelete(
1510 size_t before, size_t after) {
1511 RenderFrameHostImpl* rfh = GetFocusedFrame();
1512 if (rfh)
1513 rfh->ExtendSelectionAndDelete(before, after);
1516 void RenderWidgetHostViewAura::EnsureCaretInRect(const gfx::Rect& rect) {
1517 gfx::Rect intersected_rect(
1518 gfx::IntersectRects(rect, window_->GetBoundsInScreen()));
1520 if (intersected_rect.IsEmpty())
1521 return;
1523 host_->ScrollFocusedEditableNodeIntoRect(
1524 ConvertRectFromScreen(intersected_rect));
1527 void RenderWidgetHostViewAura::OnCandidateWindowShown() {
1528 host_->CandidateWindowShown();
1531 void RenderWidgetHostViewAura::OnCandidateWindowUpdated() {
1532 host_->CandidateWindowUpdated();
1535 void RenderWidgetHostViewAura::OnCandidateWindowHidden() {
1536 host_->CandidateWindowHidden();
1539 bool RenderWidgetHostViewAura::IsEditingCommandEnabled(int command_id) {
1540 return false;
1543 void RenderWidgetHostViewAura::ExecuteEditingCommand(int command_id) {
1546 ////////////////////////////////////////////////////////////////////////////////
1547 // RenderWidgetHostViewAura, gfx::DisplayObserver implementation:
1549 void RenderWidgetHostViewAura::OnDisplayAdded(
1550 const gfx::Display& new_display) {
1553 void RenderWidgetHostViewAura::OnDisplayRemoved(
1554 const gfx::Display& old_display) {
1557 void RenderWidgetHostViewAura::OnDisplayMetricsChanged(
1558 const gfx::Display& display, uint32_t metrics) {
1559 // The screen info should be updated regardless of the metric change.
1560 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_);
1561 if (display.id() == screen->GetDisplayNearestWindow(window_).id()) {
1562 UpdateScreenInfo(window_);
1563 current_cursor_.SetDisplayInfo(display);
1564 UpdateCursorIfOverSelf();
1568 ////////////////////////////////////////////////////////////////////////////////
1569 // RenderWidgetHostViewAura, aura::WindowDelegate implementation:
1571 gfx::Size RenderWidgetHostViewAura::GetMinimumSize() const {
1572 return gfx::Size();
1575 gfx::Size RenderWidgetHostViewAura::GetMaximumSize() const {
1576 return gfx::Size();
1579 void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
1580 const gfx::Rect& new_bounds) {
1581 base::AutoReset<bool> in_bounds_changed(&in_bounds_changed_, true);
1582 // We care about this whenever RenderWidgetHostViewAura is not owned by a
1583 // WebContentsViewAura since changes to the Window's bounds need to be
1584 // messaged to the renderer. WebContentsViewAura invokes SetSize() or
1585 // SetBounds() itself. No matter how we got here, any redundant calls are
1586 // harmless.
1587 SetSize(new_bounds.size());
1589 if (GetInputMethod())
1590 GetInputMethod()->OnCaretBoundsChanged(this);
1593 gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
1594 if (mouse_locked_)
1595 return ui::kCursorNone;
1596 return current_cursor_.GetNativeCursor();
1599 int RenderWidgetHostViewAura::GetNonClientComponent(
1600 const gfx::Point& point) const {
1601 return HTCLIENT;
1604 bool RenderWidgetHostViewAura::ShouldDescendIntoChildForEventHandling(
1605 aura::Window* child,
1606 const gfx::Point& location) {
1607 return true;
1610 bool RenderWidgetHostViewAura::CanFocus() {
1611 return popup_type_ == blink::WebPopupTypeNone;
1614 void RenderWidgetHostViewAura::OnCaptureLost() {
1615 host_->LostCapture();
1616 if (touch_editing_client_)
1617 touch_editing_client_->EndTouchEditing(false);
1620 void RenderWidgetHostViewAura::OnPaint(gfx::Canvas* canvas) {
1621 // For non-opaque windows, we don't draw anything, since we depend on the
1622 // canvas coming from the compositor to already be initialized as
1623 // transparent.
1624 if (window_->layer()->fills_bounds_opaquely())
1625 canvas->DrawColor(SK_ColorWHITE);
1628 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
1629 float device_scale_factor) {
1630 if (!host_ || !window_->GetRootWindow())
1631 return;
1633 UpdateScreenInfo(window_);
1635 const gfx::Display display = gfx::Screen::GetScreenFor(window_)->
1636 GetDisplayNearestWindow(window_);
1637 DCHECK_EQ(device_scale_factor, display.device_scale_factor());
1638 current_cursor_.SetDisplayInfo(display);
1639 SnapToPhysicalPixelBoundary();
1642 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) {
1643 #if defined(OS_WIN)
1644 HWND parent = NULL;
1645 // If the tab was hidden and it's closed, host_->is_hidden would have been
1646 // reset to false in RenderWidgetHostImpl::RendererExited.
1647 if (!window_->GetRootWindow() || host_->is_hidden()) {
1648 parent = ui::GetHiddenWindow();
1649 } else {
1650 parent = window_->GetHost()->GetAcceleratedWidget();
1652 LPARAM lparam = reinterpret_cast<LPARAM>(this);
1653 EnumChildWindows(parent, WindowDestroyingCallback, lparam);
1655 // The LegacyRenderWidgetHostHWND instance is destroyed when its window is
1656 // destroyed. Normally we control when that happens via the Destroy call
1657 // in the dtor. However there may be cases where the window is destroyed
1658 // by Windows, i.e. the parent window is destroyed before the
1659 // RenderWidgetHostViewAura instance goes away etc. To avoid that we
1660 // destroy the LegacyRenderWidgetHostHWND instance here.
1661 if (legacy_render_widget_host_HWND_) {
1662 legacy_render_widget_host_HWND_->set_host(NULL);
1663 legacy_render_widget_host_HWND_->Destroy();
1664 // The Destroy call above will delete the LegacyRenderWidgetHostHWND
1665 // instance.
1666 legacy_render_widget_host_HWND_ = NULL;
1668 #endif
1670 // Make sure that the input method no longer references to this object before
1671 // this object is removed from the root window (i.e. this object loses access
1672 // to the input method).
1673 ui::InputMethod* input_method = GetInputMethod();
1674 if (input_method)
1675 input_method->DetachTextInputClient(this);
1677 if (overscroll_controller_)
1678 overscroll_controller_->Reset();
1681 void RenderWidgetHostViewAura::OnWindowDestroyed(aura::Window* window) {
1682 host_->ViewDestroyed();
1683 delete this;
1686 void RenderWidgetHostViewAura::OnWindowTargetVisibilityChanged(bool visible) {
1689 bool RenderWidgetHostViewAura::HasHitTestMask() const {
1690 return false;
1693 void RenderWidgetHostViewAura::GetHitTestMask(gfx::Path* mask) const {
1696 ////////////////////////////////////////////////////////////////////////////////
1697 // RenderWidgetHostViewAura, ui::EventHandler implementation:
1699 void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) {
1700 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnKeyEvent");
1701 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
1702 return;
1704 if (popup_child_host_view_ && popup_child_host_view_->NeedsInputGrab()) {
1705 popup_child_host_view_->OnKeyEvent(event);
1706 if (event->handled())
1707 return;
1710 // We need to handle the Escape key for Pepper Flash.
1711 if (is_fullscreen_ && event->key_code() == ui::VKEY_ESCAPE) {
1712 // Focus the window we were created from.
1713 if (host_tracker_.get() && !host_tracker_->windows().empty()) {
1714 aura::Window* host = *(host_tracker_->windows().begin());
1715 aura::client::FocusClient* client = aura::client::GetFocusClient(host);
1716 if (client) {
1717 // Calling host->Focus() may delete |this|. We create a local observer
1718 // for that. In that case we exit without further access to any members.
1719 aura::WindowTracker tracker;
1720 aura::Window* window = window_;
1721 tracker.Add(window);
1722 host->Focus();
1723 if (!tracker.Contains(window)) {
1724 event->SetHandled();
1725 return;
1729 if (!in_shutdown_) {
1730 in_shutdown_ = true;
1731 host_->Shutdown();
1733 } else {
1734 if (event->key_code() == ui::VKEY_RETURN) {
1735 // Do not forward return key release events if no press event was handled.
1736 if (event->type() == ui::ET_KEY_RELEASED && !accept_return_character_)
1737 return;
1738 // Accept return key character events between press and release events.
1739 accept_return_character_ = event->type() == ui::ET_KEY_PRESSED;
1742 // We don't have to communicate with an input method here.
1743 if (!event->HasNativeEvent()) {
1744 NativeWebKeyboardEvent webkit_event(
1745 event->type(),
1746 event->is_char(),
1747 event->is_char() ? event->GetCharacter() : event->key_code(),
1748 event->flags(),
1749 ui::EventTimeForNow().InSecondsF());
1750 ForwardKeyboardEvent(webkit_event);
1751 } else {
1752 NativeWebKeyboardEvent webkit_event(event);
1753 ForwardKeyboardEvent(webkit_event);
1756 event->SetHandled();
1759 void RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) {
1760 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnMouseEvent");
1762 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
1763 return;
1765 if (mouse_locked_) {
1766 aura::client::CursorClient* cursor_client =
1767 aura::client::GetCursorClient(window_->GetRootWindow());
1768 DCHECK(!cursor_client || !cursor_client->IsCursorVisible());
1770 if (event->type() == ui::ET_MOUSEWHEEL) {
1771 blink::WebMouseWheelEvent mouse_wheel_event =
1772 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event));
1773 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0)
1774 host_->ForwardWheelEvent(mouse_wheel_event);
1775 return;
1778 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint());
1780 // If we receive non client mouse messages while we are in the locked state
1781 // it probably means that the mouse left the borders of our window and
1782 // needs to be moved back to the center.
1783 if (event->flags() & ui::EF_IS_NON_CLIENT) {
1784 synthetic_move_sent_ = true;
1785 window_->MoveCursorTo(center);
1786 return;
1789 blink::WebMouseEvent mouse_event = MakeWebMouseEvent(event);
1791 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED ||
1792 event->type() == ui::ET_MOUSE_DRAGGED) &&
1793 mouse_event.x == center.x() && mouse_event.y == center.y();
1795 ModifyEventMovementAndCoords(&mouse_event);
1797 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_;
1798 if (should_not_forward) {
1799 synthetic_move_sent_ = false;
1800 } else {
1801 // Check if the mouse has reached the border and needs to be centered.
1802 if (ShouldMoveToCenter()) {
1803 synthetic_move_sent_ = true;
1804 window_->MoveCursorTo(center);
1806 // Forward event to renderer.
1807 if (CanRendererHandleEvent(event) &&
1808 !(event->flags() & ui::EF_FROM_TOUCH)) {
1809 host_->ForwardMouseEvent(mouse_event);
1810 // Ensure that we get keyboard focus on mouse down as a plugin window
1811 // may have grabbed keyboard focus.
1812 if (event->type() == ui::ET_MOUSE_PRESSED)
1813 SetKeyboardFocus();
1816 return;
1819 // As the overscroll is handled during scroll events from the trackpad, the
1820 // RWHVA window is transformed by the overscroll controller. This transform
1821 // triggers a synthetic mouse-move event to be generated (by the aura
1822 // RootWindow). But this event interferes with the overscroll gesture. So,
1823 // ignore such synthetic mouse-move events if an overscroll gesture is in
1824 // progress.
1825 if (overscroll_controller_ &&
1826 overscroll_controller_->overscroll_mode() != OVERSCROLL_NONE &&
1827 event->flags() & ui::EF_IS_SYNTHESIZED &&
1828 (event->type() == ui::ET_MOUSE_ENTERED ||
1829 event->type() == ui::ET_MOUSE_EXITED ||
1830 event->type() == ui::ET_MOUSE_MOVED)) {
1831 event->StopPropagation();
1832 return;
1835 if (event->type() == ui::ET_MOUSEWHEEL) {
1836 #if defined(OS_WIN)
1837 // We get mouse wheel/scroll messages even if we are not in the foreground.
1838 // So here we check if we have any owned popup windows in the foreground and
1839 // dismiss them.
1840 aura::WindowTreeHost* host = window_->GetHost();
1841 if (host) {
1842 HWND parent = host->GetAcceleratedWidget();
1843 HWND toplevel_hwnd = ::GetAncestor(parent, GA_ROOT);
1844 EnumThreadWindows(GetCurrentThreadId(),
1845 DismissOwnedPopups,
1846 reinterpret_cast<LPARAM>(toplevel_hwnd));
1848 #endif
1849 blink::WebMouseWheelEvent mouse_wheel_event =
1850 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event));
1851 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0)
1852 host_->ForwardWheelEvent(mouse_wheel_event);
1853 } else if (CanRendererHandleEvent(event) &&
1854 !(event->flags() & ui::EF_FROM_TOUCH)) {
1855 blink::WebMouseEvent mouse_event = MakeWebMouseEvent(event);
1856 ModifyEventMovementAndCoords(&mouse_event);
1857 host_->ForwardMouseEvent(mouse_event);
1858 // Ensure that we get keyboard focus on mouse down as a plugin window may
1859 // have grabbed keyboard focus.
1860 if (event->type() == ui::ET_MOUSE_PRESSED)
1861 SetKeyboardFocus();
1864 switch (event->type()) {
1865 case ui::ET_MOUSE_PRESSED:
1866 window_->SetCapture();
1867 // Confirm existing composition text on mouse click events, to make sure
1868 // the input caret won't be moved with an ongoing composition text.
1869 FinishImeCompositionSession();
1870 break;
1871 case ui::ET_MOUSE_RELEASED:
1872 window_->ReleaseCapture();
1873 break;
1874 default:
1875 break;
1878 // Needed to propagate mouse event to |window_->parent()->delegate()|, but
1879 // note that it might be something other than a WebContentsViewAura instance.
1880 // TODO(pkotwicz): Find a better way of doing this.
1881 // In fullscreen mode which is typically used by flash, don't forward
1882 // the mouse events to the parent. The renderer and the plugin process
1883 // handle these events.
1884 if (!is_fullscreen_ && window_->parent()->delegate() &&
1885 !(event->flags() & ui::EF_FROM_TOUCH)) {
1886 event->ConvertLocationToTarget(window_, window_->parent());
1887 window_->parent()->delegate()->OnMouseEvent(event);
1890 if (!IsXButtonUpEvent(event))
1891 event->SetHandled();
1894 void RenderWidgetHostViewAura::OnScrollEvent(ui::ScrollEvent* event) {
1895 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnScrollEvent");
1896 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
1897 return;
1899 if (event->type() == ui::ET_SCROLL) {
1900 #if !defined(OS_WIN)
1901 // TODO(ananta)
1902 // Investigate if this is true for Windows 8 Metro ASH as well.
1903 if (event->finger_count() != 2)
1904 return;
1905 #endif
1906 blink::WebGestureEvent gesture_event =
1907 MakeWebGestureEventFlingCancel();
1908 host_->ForwardGestureEvent(gesture_event);
1909 blink::WebMouseWheelEvent mouse_wheel_event =
1910 MakeWebMouseWheelEvent(event);
1911 host_->ForwardWheelEvent(mouse_wheel_event);
1912 RecordAction(base::UserMetricsAction("TrackpadScroll"));
1913 } else if (event->type() == ui::ET_SCROLL_FLING_START ||
1914 event->type() == ui::ET_SCROLL_FLING_CANCEL) {
1915 blink::WebGestureEvent gesture_event =
1916 MakeWebGestureEvent(event);
1917 host_->ForwardGestureEvent(gesture_event);
1918 if (event->type() == ui::ET_SCROLL_FLING_START)
1919 RecordAction(base::UserMetricsAction("TrackpadScrollFling"));
1922 event->SetHandled();
1925 void RenderWidgetHostViewAura::OnTouchEvent(ui::TouchEvent* event) {
1926 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnTouchEvent");
1927 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
1928 return;
1930 // Update the touch event first.
1931 blink::WebTouchPoint* point = UpdateWebTouchEventFromUIEvent(*event,
1932 &touch_event_);
1934 // Forward the touch event only if a touch point was updated, and there's a
1935 // touch-event handler in the page, and no other touch-event is in the queue.
1936 // It is important to always consume the event if there is a touch-event
1937 // handler in the page, or some touch-event is already in the queue, even if
1938 // no point has been updated, to make sure that this event does not get
1939 // processed by the gesture recognizer before the events in the queue.
1940 if (host_->ShouldForwardTouchEvent())
1941 event->StopPropagation();
1943 if (point) {
1944 if (host_->ShouldForwardTouchEvent())
1945 host_->ForwardTouchEventWithLatencyInfo(touch_event_, *event->latency());
1946 UpdateWebTouchEventAfterDispatch(&touch_event_, point);
1950 void RenderWidgetHostViewAura::OnGestureEvent(ui::GestureEvent* event) {
1951 TRACE_EVENT0("input", "RenderWidgetHostViewAura::OnGestureEvent");
1952 if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN ||
1953 event->type() == ui::ET_GESTURE_PINCH_UPDATE ||
1954 event->type() == ui::ET_GESTURE_PINCH_END) && !pinch_zoom_enabled_) {
1955 event->SetHandled();
1956 return;
1959 if (touch_editing_client_ && touch_editing_client_->HandleInputEvent(event))
1960 return;
1962 RenderViewHostDelegate* delegate = NULL;
1963 if (host_->IsRenderView())
1964 delegate = RenderViewHost::From(host_)->GetDelegate();
1966 if (delegate && event->type() == ui::ET_GESTURE_BEGIN &&
1967 event->details().touch_points() == 1) {
1968 delegate->HandleGestureBegin();
1971 blink::WebGestureEvent gesture = MakeWebGestureEvent(event);
1972 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
1973 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an
1974 // event to stop any in-progress flings.
1975 blink::WebGestureEvent fling_cancel = gesture;
1976 fling_cancel.type = blink::WebInputEvent::GestureFlingCancel;
1977 fling_cancel.sourceDevice = blink::WebGestureDeviceTouchscreen;
1978 host_->ForwardGestureEvent(fling_cancel);
1981 if (gesture.type != blink::WebInputEvent::Undefined) {
1982 host_->ForwardGestureEventWithLatencyInfo(gesture, *event->latency());
1984 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
1985 event->type() == ui::ET_GESTURE_SCROLL_UPDATE ||
1986 event->type() == ui::ET_GESTURE_SCROLL_END) {
1987 RecordAction(base::UserMetricsAction("TouchscreenScroll"));
1988 } else if (event->type() == ui::ET_SCROLL_FLING_START) {
1989 RecordAction(base::UserMetricsAction("TouchscreenScrollFling"));
1993 if (delegate && event->type() == ui::ET_GESTURE_END &&
1994 event->details().touch_points() == 1) {
1995 delegate->HandleGestureEnd();
1998 // If a gesture is not processed by the webpage, then WebKit processes it
1999 // (e.g. generates synthetic mouse events).
2000 event->SetHandled();
2003 ////////////////////////////////////////////////////////////////////////////////
2004 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation:
2006 bool RenderWidgetHostViewAura::ShouldActivate() const {
2007 aura::WindowTreeHost* host = window_->GetHost();
2008 if (!host)
2009 return true;
2010 const ui::Event* event = host->dispatcher()->current_event();
2011 if (!event)
2012 return true;
2013 return is_fullscreen_;
2016 ////////////////////////////////////////////////////////////////////////////////
2017 // RenderWidgetHostViewAura,
2018 // aura::client::ActivationChangeObserver implementation:
2020 void RenderWidgetHostViewAura::OnWindowActivated(aura::Window* gained_active,
2021 aura::Window* lost_active) {
2022 DCHECK(window_ == gained_active || window_ == lost_active);
2023 if (window_ == gained_active) {
2024 const ui::Event* event = window_->GetHost()->dispatcher()->current_event();
2025 if (event && PointerEventActivates(*event))
2026 host_->OnPointerEventActivate();
2030 ////////////////////////////////////////////////////////////////////////////////
2031 // RenderWidgetHostViewAura, aura::client::CursorClientObserver implementation:
2033 void RenderWidgetHostViewAura::OnCursorVisibilityChanged(bool is_visible) {
2034 NotifyRendererOfCursorVisibilityState(is_visible);
2037 ////////////////////////////////////////////////////////////////////////////////
2038 // RenderWidgetHostViewAura, aura::client::FocusChangeObserver implementation:
2040 void RenderWidgetHostViewAura::OnWindowFocused(aura::Window* gained_focus,
2041 aura::Window* lost_focus) {
2042 DCHECK(window_ == gained_focus || window_ == lost_focus);
2043 if (window_ == gained_focus) {
2044 // We need to honor input bypass if the associated tab is does not want
2045 // input. This gives the current focused window a chance to be the text
2046 // input client and handle events.
2047 if (host_->ignore_input_events())
2048 return;
2050 host_->GotFocus();
2051 host_->SetActive(true);
2053 ui::InputMethod* input_method = GetInputMethod();
2054 if (input_method) {
2055 // Ask the system-wide IME to send all TextInputClient messages to |this|
2056 // object.
2057 input_method->SetFocusedTextInputClient(this);
2058 host_->SetInputMethodActive(input_method->IsActive());
2060 // Often the application can set focus to the view in response to a key
2061 // down. However the following char event shouldn't be sent to the web
2062 // page.
2063 host_->SuppressNextCharEvents();
2064 } else {
2065 host_->SetInputMethodActive(false);
2068 BrowserAccessibilityManager* manager =
2069 host_->GetRootBrowserAccessibilityManager();
2070 if (manager)
2071 manager->OnWindowFocused();
2072 } else if (window_ == lost_focus) {
2073 host_->SetActive(false);
2074 host_->Blur();
2076 DetachFromInputMethod();
2077 host_->SetInputMethodActive(false);
2079 if (touch_editing_client_)
2080 touch_editing_client_->EndTouchEditing(false);
2082 if (overscroll_controller_)
2083 overscroll_controller_->Cancel();
2085 BrowserAccessibilityManager* manager =
2086 host_->GetRootBrowserAccessibilityManager();
2087 if (manager)
2088 manager->OnWindowBlurred();
2090 // If we lose the focus while fullscreen, close the window; Pepper Flash
2091 // won't do it for us (unlike NPAPI Flash). However, we do not close the
2092 // window if we lose the focus to a window on another display.
2093 gfx::Screen* screen = gfx::Screen::GetScreenFor(window_);
2094 bool focusing_other_display =
2095 gained_focus && screen->GetNumDisplays() > 1 &&
2096 (screen->GetDisplayNearestWindow(window_).id() !=
2097 screen->GetDisplayNearestWindow(gained_focus).id());
2098 if (is_fullscreen_ && !in_shutdown_ && !focusing_other_display) {
2099 #if defined(OS_WIN)
2100 // On Windows, if we are switching to a non Aura Window on a different
2101 // screen we should not close the fullscreen window.
2102 if (!gained_focus) {
2103 POINT point = {0};
2104 ::GetCursorPos(&point);
2105 if (screen->GetDisplayNearestWindow(window_).id() !=
2106 screen->GetDisplayNearestPoint(gfx::Point(point)).id())
2107 return;
2109 #endif
2110 in_shutdown_ = true;
2111 host_->Shutdown();
2116 ////////////////////////////////////////////////////////////////////////////////
2117 // RenderWidgetHostViewAura, aura::WindowTreeHostObserver implementation:
2119 void RenderWidgetHostViewAura::OnHostMoved(const aura::WindowTreeHost* host,
2120 const gfx::Point& new_origin) {
2121 TRACE_EVENT1("ui", "RenderWidgetHostViewAura::OnHostMoved",
2122 "new_origin", new_origin.ToString());
2124 UpdateScreenInfo(window_);
2127 ////////////////////////////////////////////////////////////////////////////////
2128 // RenderWidgetHostViewAura, private:
2130 RenderWidgetHostViewAura::~RenderWidgetHostViewAura() {
2131 if (touch_editing_client_)
2132 touch_editing_client_->OnViewDestroyed();
2134 delegated_frame_host_.reset();
2135 window_observer_.reset();
2136 if (window_->GetHost())
2137 window_->GetHost()->RemoveObserver(this);
2138 UnlockMouse();
2139 if (popup_parent_host_view_) {
2140 DCHECK(popup_parent_host_view_->popup_child_host_view_ == NULL ||
2141 popup_parent_host_view_->popup_child_host_view_ == this);
2142 popup_parent_host_view_->popup_child_host_view_ = NULL;
2144 if (popup_child_host_view_) {
2145 DCHECK(popup_child_host_view_->popup_parent_host_view_ == NULL ||
2146 popup_child_host_view_->popup_parent_host_view_ == this);
2147 popup_child_host_view_->popup_parent_host_view_ = NULL;
2149 event_filter_for_popup_exit_.reset();
2150 aura::client::SetTooltipText(window_, NULL);
2151 gfx::Screen::GetScreenFor(window_)->RemoveObserver(this);
2153 // This call is usually no-op since |this| object is already removed from the
2154 // Aura root window and we don't have a way to get an input method object
2155 // associated with the window, but just in case.
2156 DetachFromInputMethod();
2158 #if defined(OS_WIN)
2159 // The LegacyRenderWidgetHostHWND window should have been destroyed in
2160 // RenderWidgetHostViewAura::OnWindowDestroying and the pointer should
2161 // be set to NULL.
2162 DCHECK(!legacy_render_widget_host_HWND_);
2163 #endif
2166 void RenderWidgetHostViewAura::UpdateCursorIfOverSelf() {
2167 const gfx::Point screen_point =
2168 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint();
2169 aura::Window* root_window = window_->GetRootWindow();
2170 if (!root_window)
2171 return;
2173 gfx::Point root_window_point = screen_point;
2174 aura::client::ScreenPositionClient* screen_position_client =
2175 aura::client::GetScreenPositionClient(root_window);
2176 if (screen_position_client) {
2177 screen_position_client->ConvertPointFromScreen(
2178 root_window, &root_window_point);
2181 if (root_window->GetEventHandlerForPoint(root_window_point) != window_)
2182 return;
2184 gfx::NativeCursor cursor = current_cursor_.GetNativeCursor();
2185 // Do not show loading cursor when the cursor is currently hidden.
2186 if (is_loading_ && cursor != ui::kCursorNone)
2187 cursor = ui::kCursorPointer;
2189 aura::client::CursorClient* cursor_client =
2190 aura::client::GetCursorClient(root_window);
2191 if (cursor_client) {
2192 cursor_client->SetCursor(cursor);
2196 ui::InputMethod* RenderWidgetHostViewAura::GetInputMethod() const {
2197 aura::Window* root_window = window_->GetRootWindow();
2198 if (!root_window)
2199 return NULL;
2200 return root_window->GetProperty(aura::client::kRootWindowInputMethodKey);
2203 bool RenderWidgetHostViewAura::NeedsInputGrab() {
2204 return popup_type_ == blink::WebPopupTypeSelect;
2207 void RenderWidgetHostViewAura::FinishImeCompositionSession() {
2208 if (!has_composition_text_)
2209 return;
2210 if (host_) {
2211 host_->ImeConfirmComposition(base::string16(), gfx::Range::InvalidRange(),
2212 false);
2214 ImeCancelComposition();
2217 void RenderWidgetHostViewAura::ModifyEventMovementAndCoords(
2218 blink::WebMouseEvent* event) {
2219 // If the mouse has just entered, we must report zero movementX/Y. Hence we
2220 // reset any global_mouse_position set previously.
2221 if (event->type == blink::WebInputEvent::MouseEnter ||
2222 event->type == blink::WebInputEvent::MouseLeave)
2223 global_mouse_position_.SetPoint(event->globalX, event->globalY);
2225 // Movement is computed by taking the difference of the new cursor position
2226 // and the previous. Under mouse lock the cursor will be warped back to the
2227 // center so that we are not limited by clipping boundaries.
2228 // We do not measure movement as the delta from cursor to center because
2229 // we may receive more mouse movement events before our warp has taken
2230 // effect.
2231 event->movementX = event->globalX - global_mouse_position_.x();
2232 event->movementY = event->globalY - global_mouse_position_.y();
2234 global_mouse_position_.SetPoint(event->globalX, event->globalY);
2236 // Under mouse lock, coordinates of mouse are locked to what they were when
2237 // mouse lock was entered.
2238 if (mouse_locked_) {
2239 event->x = unlocked_mouse_position_.x();
2240 event->y = unlocked_mouse_position_.y();
2241 event->windowX = unlocked_mouse_position_.x();
2242 event->windowY = unlocked_mouse_position_.y();
2243 event->globalX = unlocked_global_mouse_position_.x();
2244 event->globalY = unlocked_global_mouse_position_.y();
2245 } else {
2246 unlocked_mouse_position_.SetPoint(event->windowX, event->windowY);
2247 unlocked_global_mouse_position_.SetPoint(event->globalX, event->globalY);
2251 void RenderWidgetHostViewAura::NotifyRendererOfCursorVisibilityState(
2252 bool is_visible) {
2253 if (host_->is_hidden() ||
2254 (cursor_visibility_state_in_renderer_ == VISIBLE && is_visible) ||
2255 (cursor_visibility_state_in_renderer_ == NOT_VISIBLE && !is_visible))
2256 return;
2258 cursor_visibility_state_in_renderer_ = is_visible ? VISIBLE : NOT_VISIBLE;
2259 host_->SendCursorVisibilityState(is_visible);
2262 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) {
2263 if (!enabled)
2264 overscroll_controller_.reset();
2265 else if (!overscroll_controller_)
2266 overscroll_controller_.reset(new OverscrollController());
2269 void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() {
2270 // The top left corner of our view in window coordinates might not land on a
2271 // device pixel boundary if we have a non-integer device scale. In that case,
2272 // to avoid the web contents area looking blurry we translate the web contents
2273 // in the +x, +y direction to land on the nearest pixel boundary. This may
2274 // cause the bottom and right edges to be clipped slightly, but that's ok.
2275 aura::Window* snapped = NULL;
2276 // On desktop, use the root window. On alternative environment (ash),
2277 // use the toplevel window which must be already snapped.
2278 if (gfx::Screen::GetScreenFor(window_) !=
2279 gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE)) {
2280 snapped = window_->GetRootWindow();
2281 } else {
2282 snapped = window_->GetToplevelWindow();
2284 if (snapped && snapped != window_)
2285 ui::SnapLayerToPhysicalPixelBoundary(snapped->layer(), window_->layer());
2287 has_snapped_to_boundary_ = true;
2290 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
2291 if (HasDisplayPropertyChanged(window_))
2292 host_->InvalidateScreenInfo();
2294 SnapToPhysicalPixelBoundary();
2295 // Don't recursively call SetBounds if this bounds update is the result of
2296 // a Window::SetBoundsInternal call.
2297 if (!in_bounds_changed_)
2298 window_->SetBounds(rect);
2299 host_->WasResized();
2300 delegated_frame_host_->WasResized();
2301 if (touch_editing_client_) {
2302 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_,
2303 selection_focus_rect_);
2305 #if defined(OS_WIN)
2306 // Create the legacy dummy window which corresponds to the bounds of the
2307 // webcontents. This will be passed as the container window for windowless
2308 // plugins.
2309 // Plugins like Flash assume the container window which is returned via the
2310 // NPNVnetscapeWindow property corresponds to the bounds of the webpage.
2311 // This is not true in Aura where we have only HWND which is the main Aura
2312 // window. If we return this window to plugins like Flash then it causes the
2313 // coordinate translations done by these plugins to break.
2314 // Additonally the legacy dummy window is needed for accessibility and for
2315 // scrolling to work in legacy drivers for trackpoints/trackpads, etc.
2316 if (!legacy_window_destroyed_ && GetNativeViewId()) {
2317 if (!legacy_render_widget_host_HWND_) {
2318 legacy_render_widget_host_HWND_ = LegacyRenderWidgetHostHWND::Create(
2319 reinterpret_cast<HWND>(GetNativeViewId()));
2321 if (legacy_render_widget_host_HWND_) {
2322 legacy_render_widget_host_HWND_->set_host(this);
2323 legacy_render_widget_host_HWND_->SetBounds(
2324 window_->GetBoundsInRootWindow());
2325 // There are cases where the parent window is created, made visible and
2326 // the associated RenderWidget is also visible before the
2327 // LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown
2328 // here.
2329 if (!host_->is_hidden())
2330 legacy_render_widget_host_HWND_->Show();
2334 if (mouse_locked_)
2335 UpdateMouseLockRegion();
2336 #endif
2339 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip(
2340 const gfx::Rect& rect,
2341 const gfx::Rect& clip) {
2342 if (!clip.IsEmpty()) {
2343 gfx::Rect to_paint = gfx::SubtractRects(rect, clip);
2344 if (!to_paint.IsEmpty())
2345 window_->SchedulePaintInRect(to_paint);
2346 } else {
2347 window_->SchedulePaintInRect(rect);
2351 bool RenderWidgetHostViewAura::ShouldMoveToCenter() {
2352 gfx::Rect rect = window_->bounds();
2353 rect = ConvertRectToScreen(rect);
2354 int border_x = rect.width() * kMouseLockBorderPercentage / 100;
2355 int border_y = rect.height() * kMouseLockBorderPercentage / 100;
2357 return global_mouse_position_.x() < rect.x() + border_x ||
2358 global_mouse_position_.x() > rect.right() - border_x ||
2359 global_mouse_position_.y() < rect.y() + border_y ||
2360 global_mouse_position_.y() > rect.bottom() - border_y;
2363 void RenderWidgetHostViewAura::AddedToRootWindow() {
2364 window_->GetHost()->AddObserver(this);
2365 UpdateScreenInfo(window_);
2367 aura::client::CursorClient* cursor_client =
2368 aura::client::GetCursorClient(window_->GetRootWindow());
2369 if (cursor_client) {
2370 cursor_client->AddObserver(this);
2371 NotifyRendererOfCursorVisibilityState(cursor_client->IsCursorVisible());
2373 if (HasFocus()) {
2374 ui::InputMethod* input_method = GetInputMethod();
2375 if (input_method)
2376 input_method->SetFocusedTextInputClient(this);
2379 #if defined(OS_WIN)
2380 // The parent may have changed here. Ensure that the legacy window is
2381 // reparented accordingly.
2382 if (legacy_render_widget_host_HWND_)
2383 legacy_render_widget_host_HWND_->UpdateParent(
2384 reinterpret_cast<HWND>(GetNativeViewId()));
2385 #endif
2387 delegated_frame_host_->AddedToWindow();
2390 void RenderWidgetHostViewAura::RemovingFromRootWindow() {
2391 aura::client::CursorClient* cursor_client =
2392 aura::client::GetCursorClient(window_->GetRootWindow());
2393 if (cursor_client)
2394 cursor_client->RemoveObserver(this);
2396 DetachFromInputMethod();
2398 window_->GetHost()->RemoveObserver(this);
2399 delegated_frame_host_->RemovingFromWindow();
2401 #if defined(OS_WIN)
2402 // Update the legacy window's parent temporarily to the desktop window. It
2403 // will eventually get reparented to the right root.
2404 if (legacy_render_widget_host_HWND_)
2405 legacy_render_widget_host_HWND_->UpdateParent(::GetDesktopWindow());
2406 #endif
2409 void RenderWidgetHostViewAura::DetachFromInputMethod() {
2410 ui::InputMethod* input_method = GetInputMethod();
2411 if (input_method && input_method->GetTextInputClient() == this)
2412 input_method->SetFocusedTextInputClient(NULL);
2415 void RenderWidgetHostViewAura::ForwardKeyboardEvent(
2416 const NativeWebKeyboardEvent& event) {
2417 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
2418 ui::TextEditKeyBindingsDelegateAuraLinux* keybinding_delegate =
2419 ui::GetTextEditKeyBindingsDelegate();
2420 std::vector<ui::TextEditCommandAuraLinux> commands;
2421 if (!event.skip_in_browser &&
2422 keybinding_delegate &&
2423 event.os_event &&
2424 keybinding_delegate->MatchEvent(*event.os_event, &commands)) {
2425 // Transform from ui/ types to content/ types.
2426 EditCommands edit_commands;
2427 for (std::vector<ui::TextEditCommandAuraLinux>::const_iterator it =
2428 commands.begin(); it != commands.end(); ++it) {
2429 edit_commands.push_back(EditCommand(it->GetCommandString(),
2430 it->argument()));
2432 host_->Send(new InputMsg_SetEditCommandsForNextKeyEvent(
2433 host_->GetRoutingID(), edit_commands));
2434 NativeWebKeyboardEvent copy_event(event);
2435 copy_event.match_edit_command = true;
2436 host_->ForwardKeyboardEvent(copy_event);
2437 return;
2439 #endif
2441 host_->ForwardKeyboardEvent(event);
2444 SkColorType RenderWidgetHostViewAura::PreferredReadbackFormat() {
2445 return kN32_SkColorType;
2448 ////////////////////////////////////////////////////////////////////////////////
2449 // DelegatedFrameHost, public:
2451 ui::Compositor* RenderWidgetHostViewAura::GetCompositor() const {
2452 aura::WindowTreeHost* host = window_->GetHost();
2453 return host ? host->compositor() : NULL;
2456 ui::Layer* RenderWidgetHostViewAura::GetLayer() {
2457 return window_->layer();
2460 RenderWidgetHostImpl* RenderWidgetHostViewAura::GetHost() {
2461 return host_;
2464 bool RenderWidgetHostViewAura::IsVisible() {
2465 return IsShowing();
2468 gfx::Size RenderWidgetHostViewAura::DesiredFrameSize() {
2469 return window_->bounds().size();
2472 float RenderWidgetHostViewAura::CurrentDeviceScaleFactor() {
2473 return current_device_scale_factor_;
2476 gfx::Size RenderWidgetHostViewAura::ConvertViewSizeToPixel(
2477 const gfx::Size& size) {
2478 return content::ConvertViewSizeToPixel(this, size);
2481 scoped_ptr<ResizeLock> RenderWidgetHostViewAura::CreateResizeLock(
2482 bool defer_compositor_lock) {
2483 gfx::Size desired_size = window_->bounds().size();
2484 return scoped_ptr<ResizeLock>(new CompositorResizeLock(
2485 window_->GetHost(),
2486 desired_size,
2487 defer_compositor_lock,
2488 base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs)));
2491 DelegatedFrameHost* RenderWidgetHostViewAura::GetDelegatedFrameHost() const {
2492 return delegated_frame_host_.get();
2495 ////////////////////////////////////////////////////////////////////////////////
2496 // RenderWidgetHostViewBase, public:
2498 // static
2499 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2500 GetScreenInfoForWindow(results, NULL);
2503 } // namespace content