OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return pinch_allowed; | 168 return pinch_allowed; |
169 } | 169 } |
170 | 170 |
171 bool ShouldReleaseFrontSurface() { | 171 bool ShouldReleaseFrontSurface() { |
172 static bool release_front_surface_allowed = | 172 static bool release_front_surface_allowed = |
173 CommandLine::ForCurrentProcess()->HasSwitch( | 173 CommandLine::ForCurrentProcess()->HasSwitch( |
174 switches::kEnableUIReleaseFrontSurface); | 174 switches::kEnableUIReleaseFrontSurface); |
175 return release_front_surface_allowed; | 175 return release_front_surface_allowed; |
176 } | 176 } |
177 | 177 |
| 178 bool PointerEventActivates(const ui::Event& event) { |
| 179 if (event.type() == ui::ET_MOUSE_PRESSED) |
| 180 return true; |
| 181 |
| 182 if (event.type() == ui::ET_GESTURE_BEGIN) { |
| 183 const ui::GestureEvent& gesture = |
| 184 static_cast<const ui::GestureEvent&>(event); |
| 185 return gesture.details().touch_points() == 1; |
| 186 } |
| 187 |
| 188 return false; |
| 189 } |
| 190 |
178 } // namespace | 191 } // namespace |
179 | 192 |
180 // We have to implement the WindowObserver interface on a separate object | 193 // We have to implement the WindowObserver interface on a separate object |
181 // because clang doesn't like implementing multiple interfaces that have | 194 // because clang doesn't like implementing multiple interfaces that have |
182 // methods with the same name. This object is owned by the | 195 // methods with the same name. This object is owned by the |
183 // RenderWidgetHostViewAura. | 196 // RenderWidgetHostViewAura. |
184 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver { | 197 class RenderWidgetHostViewAura::WindowObserver : public aura::WindowObserver { |
185 public: | 198 public: |
186 explicit WindowObserver(RenderWidgetHostViewAura* view) : view_(view) {} | 199 explicit WindowObserver(RenderWidgetHostViewAura* view) : view_(view) {} |
187 virtual ~WindowObserver() {} | 200 virtual ~WindowObserver() {} |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 has_composition_text_(false), | 291 has_composition_text_(false), |
279 device_scale_factor_(1.0f), | 292 device_scale_factor_(1.0f), |
280 current_surface_(0), | 293 current_surface_(0), |
281 current_surface_is_protected_(true), | 294 current_surface_is_protected_(true), |
282 current_surface_in_use_by_compositor_(true), | 295 current_surface_in_use_by_compositor_(true), |
283 protection_state_id_(0), | 296 protection_state_id_(0), |
284 surface_route_id_(0), | 297 surface_route_id_(0), |
285 paint_canvas_(NULL), | 298 paint_canvas_(NULL), |
286 synthetic_move_sent_(false), | 299 synthetic_move_sent_(false), |
287 accelerated_compositing_state_changed_(false), | 300 accelerated_compositing_state_changed_(false), |
288 can_lock_compositor_(YES), | 301 can_lock_compositor_(YES) { |
289 pointer_activate_(false) { | |
290 host_->SetView(this); | 302 host_->SetView(this); |
291 window_observer_.reset(new WindowObserver(this)); | 303 window_observer_.reset(new WindowObserver(this)); |
292 window_->AddObserver(window_observer_.get()); | 304 window_->AddObserver(window_observer_.get()); |
293 aura::client::SetTooltipText(window_, &tooltip_); | 305 aura::client::SetTooltipText(window_, &tooltip_); |
294 aura::client::SetActivationDelegate(window_, this); | 306 aura::client::SetActivationDelegate(window_, this); |
295 gfx::Screen::GetScreenFor(window_)->AddObserver(this); | 307 gfx::Screen::GetScreenFor(window_)->AddObserver(this); |
296 } | 308 } |
297 | 309 |
298 //////////////////////////////////////////////////////////////////////////////// | 310 //////////////////////////////////////////////////////////////////////////////// |
299 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: | 311 // RenderWidgetHostViewAura, RenderWidgetHostView implementation: |
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 } else { | 1547 } else { |
1536 NativeWebKeyboardEvent webkit_event(event); | 1548 NativeWebKeyboardEvent webkit_event(event); |
1537 host_->ForwardKeyboardEvent(webkit_event); | 1549 host_->ForwardKeyboardEvent(webkit_event); |
1538 } | 1550 } |
1539 } | 1551 } |
1540 return ui::ER_HANDLED; | 1552 return ui::ER_HANDLED; |
1541 } | 1553 } |
1542 | 1554 |
1543 ui::EventResult RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { | 1555 ui::EventResult RenderWidgetHostViewAura::OnMouseEvent(ui::MouseEvent* event) { |
1544 TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnMouseEvent"); | 1556 TRACE_EVENT0("browser", "RenderWidgetHostViewAura::OnMouseEvent"); |
1545 pointer_activate_ = event->type() == ui::ET_MOUSE_PRESSED; | |
1546 | 1557 |
1547 if (mouse_locked_) { | 1558 if (mouse_locked_) { |
1548 // Hide the cursor if someone else has shown it. | 1559 // Hide the cursor if someone else has shown it. |
1549 aura::client::CursorClient* cursor_client = | 1560 aura::client::CursorClient* cursor_client = |
1550 aura::client::GetCursorClient(window_->GetRootWindow()); | 1561 aura::client::GetCursorClient(window_->GetRootWindow()); |
1551 if (cursor_client && cursor_client->IsCursorVisible()) | 1562 if (cursor_client && cursor_client->IsCursorVisible()) |
1552 cursor_client->ShowCursor(false); | 1563 cursor_client->ShowCursor(false); |
1553 | 1564 |
1554 WebKit::WebMouseEvent mouse_event = MakeWebMouseEvent(event); | 1565 WebKit::WebMouseEvent mouse_event = MakeWebMouseEvent(event); |
1555 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); | 1566 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1678 if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN || | 1689 if ((event->type() == ui::ET_GESTURE_PINCH_BEGIN || |
1679 event->type() == ui::ET_GESTURE_PINCH_UPDATE || | 1690 event->type() == ui::ET_GESTURE_PINCH_UPDATE || |
1680 event->type() == ui::ET_GESTURE_PINCH_END) && !ShouldSendPinchGesture()) { | 1691 event->type() == ui::ET_GESTURE_PINCH_END) && !ShouldSendPinchGesture()) { |
1681 return ui::ER_CONSUMED; | 1692 return ui::ER_CONSUMED; |
1682 } | 1693 } |
1683 | 1694 |
1684 RenderViewHostDelegate* delegate = NULL; | 1695 RenderViewHostDelegate* delegate = NULL; |
1685 if (popup_type_ == WebKit::WebPopupTypeNone && !is_fullscreen_) | 1696 if (popup_type_ == WebKit::WebPopupTypeNone && !is_fullscreen_) |
1686 delegate = RenderViewHost::From(host_)->GetDelegate(); | 1697 delegate = RenderViewHost::From(host_)->GetDelegate(); |
1687 | 1698 |
1688 bool gesture_begin = event->type() == ui::ET_GESTURE_BEGIN && | 1699 if (delegate && event->type() == ui::ET_GESTURE_BEGIN && |
1689 event->details().touch_points() == 1; | 1700 event->details().touch_points() == 1) { |
1690 if (delegate && gesture_begin) | |
1691 delegate->HandleGestureBegin(); | 1701 delegate->HandleGestureBegin(); |
1692 pointer_activate_ = gesture_begin; | 1702 } |
1693 | 1703 |
1694 WebKit::WebGestureEvent gesture = MakeWebGestureEvent(event); | 1704 WebKit::WebGestureEvent gesture = MakeWebGestureEvent(event); |
1695 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 1705 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
1696 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an | 1706 // Webkit does not stop a fling-scroll on tap-down. So explicitly send an |
1697 // event to stop any in-progress flings. | 1707 // event to stop any in-progress flings. |
1698 WebKit::WebGestureEvent fling_cancel = gesture; | 1708 WebKit::WebGestureEvent fling_cancel = gesture; |
1699 fling_cancel.type = WebKit::WebInputEvent::GestureFlingCancel; | 1709 fling_cancel.type = WebKit::WebInputEvent::GestureFlingCancel; |
1700 host_->ForwardGestureEvent(fling_cancel); | 1710 host_->ForwardGestureEvent(fling_cancel); |
1701 } | 1711 } |
1702 | 1712 |
(...skipping 18 matching lines...) Expand all Loading... |
1721 // (e.g. generates synthetic mouse events). So CONSUMED should be returned | 1731 // (e.g. generates synthetic mouse events). So CONSUMED should be returned |
1722 // from here to avoid any duplicate synthetic mouse-events being generated | 1732 // from here to avoid any duplicate synthetic mouse-events being generated |
1723 // from aura. | 1733 // from aura. |
1724 return ui::ER_CONSUMED; | 1734 return ui::ER_CONSUMED; |
1725 } | 1735 } |
1726 | 1736 |
1727 //////////////////////////////////////////////////////////////////////////////// | 1737 //////////////////////////////////////////////////////////////////////////////// |
1728 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation: | 1738 // RenderWidgetHostViewAura, aura::client::ActivationDelegate implementation: |
1729 | 1739 |
1730 bool RenderWidgetHostViewAura::ShouldActivate() const { | 1740 bool RenderWidgetHostViewAura::ShouldActivate() const { |
| 1741 const ui::Event* event = window_->GetRootWindow()->current_event(); |
| 1742 if (!event) |
| 1743 return true; |
1731 return is_fullscreen_; | 1744 return is_fullscreen_; |
1732 } | 1745 } |
1733 | 1746 |
1734 void RenderWidgetHostViewAura::OnActivated() { | 1747 void RenderWidgetHostViewAura::OnActivated() { |
1735 // |pointer_activate_| will be true when we are activated as the result of | 1748 const ui::Event* event = window_->GetRootWindow()->current_event(); |
1736 // a valid input event. | 1749 if (event && PointerEventActivates(*event)) |
1737 // TODO(sadrul): It would be nice if we could get the currently processed | |
1738 // event from the RootWindow's EventDispatcher, then we could | |
1739 // avoid this extra field and just check the type/details on | |
1740 // the current event here. | |
1741 if (pointer_activate_) | |
1742 host_->OnPointerEventActivate(); | 1750 host_->OnPointerEventActivate(); |
1743 } | 1751 } |
1744 | 1752 |
1745 void RenderWidgetHostViewAura::OnLostActive() { | 1753 void RenderWidgetHostViewAura::OnLostActive() { |
1746 } | 1754 } |
1747 | 1755 |
1748 //////////////////////////////////////////////////////////////////////////////// | 1756 //////////////////////////////////////////////////////////////////////////////// |
1749 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: | 1757 // RenderWidgetHostViewAura, ui::CompositorObserver implementation: |
1750 | 1758 |
1751 void RenderWidgetHostViewAura::OnCompositingDidCommit( | 1759 void RenderWidgetHostViewAura::OnCompositingDidCommit( |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 RenderWidgetHost* widget) { | 2007 RenderWidgetHost* widget) { |
2000 return new RenderWidgetHostViewAura(widget); | 2008 return new RenderWidgetHostViewAura(widget); |
2001 } | 2009 } |
2002 | 2010 |
2003 // static | 2011 // static |
2004 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 2012 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
2005 GetScreenInfoForWindow(results, NULL); | 2013 GetScreenInfoForWindow(results, NULL); |
2006 } | 2014 } |
2007 | 2015 |
2008 } // namespace content | 2016 } // namespace content |
OLD | NEW |