 Chromium Code Reviews
 Chromium Code Reviews Issue 49383004:
  Ensure on Windows AURA that the cursor stays within the bounds of the window during a LockMouse ope…  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/
    
  
    Issue 49383004:
  Ensure on Windows AURA that the cursor stays within the bounds of the window during a LockMouse ope…  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/| 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/basictypes.h" | 7 #include "base/basictypes.h" | 
| 8 #include "base/bind.h" | 8 #include "base/bind.h" | 
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" | 
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" | 
| (...skipping 2152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2163 if (shared_surface_handle_.is_null()) { | 2163 if (shared_surface_handle_.is_null()) { | 
| 2164 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 2164 ImageTransportFactory* factory = ImageTransportFactory::GetInstance(); | 
| 2165 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); | 2165 shared_surface_handle_ = factory->CreateSharedSurfaceHandle(); | 
| 2166 if (!shared_surface_handle_.is_null()) | 2166 if (!shared_surface_handle_.is_null()) | 
| 2167 factory->AddObserver(this); | 2167 factory->AddObserver(this); | 
| 2168 } | 2168 } | 
| 2169 return shared_surface_handle_; | 2169 return shared_surface_handle_; | 
| 2170 } | 2170 } | 
| 2171 | 2171 | 
| 2172 bool RenderWidgetHostViewAura::LockMouse() { | 2172 bool RenderWidgetHostViewAura::LockMouse() { | 
| 2173 aura::Window* root_window = window_->GetRootWindow(); | 2173 aura::RootWindow* root_window = | 
| 2174 static_cast<aura::RootWindow*>(window_->GetRootWindow()); | |
| 
scheib
2013/10/30 21:23:07
Why doesn't GetRootWindow() return a RootWindow?
 
ananta
2013/10/30 21:43:15
Checked with sky and ben. The RootWindow class is
 | |
| 2174 if (!root_window) | 2175 if (!root_window) | 
| 2175 return false; | 2176 return false; | 
| 2176 | 2177 | 
| 2177 if (mouse_locked_) | 2178 if (mouse_locked_) | 
| 2178 return true; | 2179 return true; | 
| 2179 | 2180 | 
| 2180 mouse_locked_ = true; | 2181 mouse_locked_ = true; | 
| 2181 #if !defined(OS_WIN) | 2182 #if !defined(OS_WIN) | 
| 2182 window_->SetCapture(); | 2183 window_->SetCapture(); | 
| 2183 #endif | 2184 #endif | 
| 2184 aura::client::CursorClient* cursor_client = | 2185 aura::client::CursorClient* cursor_client = | 
| 2185 aura::client::GetCursorClient(root_window); | 2186 aura::client::GetCursorClient(root_window); | 
| 2186 if (cursor_client) { | 2187 if (cursor_client) { | 
| 2187 cursor_client->HideCursor(); | 2188 cursor_client->HideCursor(); | 
| 2188 cursor_client->LockCursor(); | 2189 cursor_client->LockCursor(); | 
| 2189 } | 2190 } | 
| 2190 | 2191 | 
| 2191 if (ShouldMoveToCenter()) { | 2192 if (ShouldMoveToCenter()) { | 
| 2192 synthetic_move_sent_ = true; | 2193 synthetic_move_sent_ = true; | 
| 2193 window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint()); | 2194 window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint()); | 
| 2194 } | 2195 } | 
| 2195 if (aura::client::GetTooltipClient(root_window)) | 2196 if (aura::client::GetTooltipClient(root_window)) | 
| 2196 aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(false); | 2197 aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(false); | 
| 2198 | |
| 2199 root_window->ConfineCursorToWindow(); | |
| 2197 return true; | 2200 return true; | 
| 2198 } | 2201 } | 
| 2199 | 2202 | 
| 2200 void RenderWidgetHostViewAura::UnlockMouse() { | 2203 void RenderWidgetHostViewAura::UnlockMouse() { | 
| 2201 aura::Window* root_window = window_->GetRootWindow(); | 2204 aura::RootWindow* root_window = | 
| 2205 static_cast<aura::RootWindow*>(window_->GetRootWindow()); | |
| 2202 if (!mouse_locked_ || !root_window) | 2206 if (!mouse_locked_ || !root_window) | 
| 2203 return; | 2207 return; | 
| 2204 | 2208 | 
| 2205 mouse_locked_ = false; | 2209 mouse_locked_ = false; | 
| 2206 | 2210 | 
| 2207 #if !defined(OS_WIN) | 2211 #if !defined(OS_WIN) | 
| 2208 window_->ReleaseCapture(); | 2212 window_->ReleaseCapture(); | 
| 2209 #endif | 2213 #endif | 
| 2210 window_->MoveCursorTo(unlocked_mouse_position_); | 2214 window_->MoveCursorTo(unlocked_mouse_position_); | 
| 2211 aura::client::CursorClient* cursor_client = | 2215 aura::client::CursorClient* cursor_client = | 
| 2212 aura::client::GetCursorClient(root_window); | 2216 aura::client::GetCursorClient(root_window); | 
| 2213 if (cursor_client) { | 2217 if (cursor_client) { | 
| 2214 cursor_client->UnlockCursor(); | 2218 cursor_client->UnlockCursor(); | 
| 2215 cursor_client->ShowCursor(); | 2219 cursor_client->ShowCursor(); | 
| 2216 } | 2220 } | 
| 2217 | 2221 | 
| 2218 if (aura::client::GetTooltipClient(root_window)) | 2222 if (aura::client::GetTooltipClient(root_window)) | 
| 2219 aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(true); | 2223 aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(true); | 
| 2220 | 2224 | 
| 2221 host_->LostMouseLock(); | 2225 host_->LostMouseLock(); | 
| 2226 root_window->UnConfineCursor(); | |
| 2222 } | 2227 } | 
| 2223 | 2228 | 
| 2224 //////////////////////////////////////////////////////////////////////////////// | 2229 //////////////////////////////////////////////////////////////////////////////// | 
| 2225 // RenderWidgetHostViewAura, ui::TextInputClient implementation: | 2230 // RenderWidgetHostViewAura, ui::TextInputClient implementation: | 
| 2226 void RenderWidgetHostViewAura::SetCompositionText( | 2231 void RenderWidgetHostViewAura::SetCompositionText( | 
| 2227 const ui::CompositionText& composition) { | 2232 const ui::CompositionText& composition) { | 
| 2228 if (!host_) | 2233 if (!host_) | 
| 2229 return; | 2234 return; | 
| 2230 | 2235 | 
| 2231 // ui::CompositionUnderline should be identical to | 2236 // ui::CompositionUnderline should be identical to | 
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2723 DCHECK(!cursor_client || !cursor_client->IsCursorVisible()); | 2728 DCHECK(!cursor_client || !cursor_client->IsCursorVisible()); | 
| 2724 | 2729 | 
| 2725 if (event->type() == ui::ET_MOUSEWHEEL) { | 2730 if (event->type() == ui::ET_MOUSEWHEEL) { | 
| 2726 WebKit::WebMouseWheelEvent mouse_wheel_event = | 2731 WebKit::WebMouseWheelEvent mouse_wheel_event = | 
| 2727 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event)); | 2732 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event)); | 
| 2728 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) | 2733 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) | 
| 2729 host_->ForwardWheelEvent(mouse_wheel_event); | 2734 host_->ForwardWheelEvent(mouse_wheel_event); | 
| 2730 return; | 2735 return; | 
| 2731 } | 2736 } | 
| 2732 | 2737 | 
| 2738 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); | |
| 2739 | |
| 2740 // If we receive non client mouse messages while we are in the locked state | |
| 2741 // it probably means that the mouse left the borders of our window and | |
| 2742 // needs to be moved back to the center. | |
| 2743 if (event->flags() & ui::EF_IS_NON_CLIENT) { | |
| 2744 synthetic_move_sent_ = true; | |
| 2745 window_->MoveCursorTo(center); | |
| 2746 return; | |
| 2747 } | |
| 2748 | |
| 2733 WebKit::WebMouseEvent mouse_event = MakeWebMouseEvent(event); | 2749 WebKit::WebMouseEvent mouse_event = MakeWebMouseEvent(event); | 
| 2734 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); | |
| 2735 | 2750 | 
| 2736 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || | 2751 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || | 
| 2737 event->type() == ui::ET_MOUSE_DRAGGED) && | 2752 event->type() == ui::ET_MOUSE_DRAGGED) && | 
| 2738 mouse_event.x == center.x() && mouse_event.y == center.y(); | 2753 mouse_event.x == center.x() && mouse_event.y == center.y(); | 
| 2739 | 2754 | 
| 2740 ModifyEventMovementAndCoords(&mouse_event); | 2755 ModifyEventMovementAndCoords(&mouse_event); | 
| 2741 | 2756 | 
| 2742 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; | 2757 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; | 
| 2743 if (should_not_forward) { | 2758 if (should_not_forward) { | 
| 2744 synthetic_move_sent_ = false; | 2759 synthetic_move_sent_ = false; | 
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3425 RenderWidgetHost* widget) { | 3440 RenderWidgetHost* widget) { | 
| 3426 return new RenderWidgetHostViewAura(widget); | 3441 return new RenderWidgetHostViewAura(widget); | 
| 3427 } | 3442 } | 
| 3428 | 3443 | 
| 3429 // static | 3444 // static | 
| 3430 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3445 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 
| 3431 GetScreenInfoForWindow(results, NULL); | 3446 GetScreenInfoForWindow(results, NULL); | 
| 3432 } | 3447 } | 
| 3433 | 3448 | 
| 3434 } // namespace content | 3449 } // namespace content | 
| OLD | NEW |