| 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::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); |
| 2174 if (!root_window) | 2174 if (!dispatcher) |
| 2175 return false; | 2175 return false; |
| 2176 | 2176 |
| 2177 if (mouse_locked_) | 2177 if (mouse_locked_) |
| 2178 return true; | 2178 return true; |
| 2179 | 2179 |
| 2180 mouse_locked_ = true; | 2180 mouse_locked_ = true; |
| 2181 #if !defined(OS_WIN) | 2181 #if !defined(OS_WIN) |
| 2182 window_->SetCapture(); | 2182 window_->SetCapture(); |
| 2183 #endif | 2183 #endif |
| 2184 aura::client::CursorClient* cursor_client = | 2184 aura::client::CursorClient* cursor_client = |
| 2185 aura::client::GetCursorClient(root_window); | 2185 aura::client::GetCursorClient(dispatcher); |
| 2186 if (cursor_client) { | 2186 if (cursor_client) { |
| 2187 cursor_client->HideCursor(); | 2187 cursor_client->HideCursor(); |
| 2188 cursor_client->LockCursor(); | 2188 cursor_client->LockCursor(); |
| 2189 } | 2189 } |
| 2190 | 2190 |
| 2191 if (ShouldMoveToCenter()) { | 2191 if (ShouldMoveToCenter()) { |
| 2192 synthetic_move_sent_ = true; | 2192 synthetic_move_sent_ = true; |
| 2193 window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint()); | 2193 window_->MoveCursorTo(gfx::Rect(window_->bounds().size()).CenterPoint()); |
| 2194 } | 2194 } |
| 2195 if (aura::client::GetTooltipClient(root_window)) | 2195 if (aura::client::GetTooltipClient(dispatcher)) |
| 2196 aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(false); | 2196 aura::client::GetTooltipClient(dispatcher)->SetTooltipsEnabled(false); |
| 2197 |
| 2198 dispatcher->ConfineCursorToWindow(); |
| 2197 return true; | 2199 return true; |
| 2198 } | 2200 } |
| 2199 | 2201 |
| 2200 void RenderWidgetHostViewAura::UnlockMouse() { | 2202 void RenderWidgetHostViewAura::UnlockMouse() { |
| 2201 aura::Window* root_window = window_->GetRootWindow(); | 2203 aura::WindowEventDispatcher* dispatcher = window_->GetDispatcher(); |
| 2202 if (!mouse_locked_ || !root_window) | 2204 if (!mouse_locked_ || !dispatcher) |
| 2203 return; | 2205 return; |
| 2204 | 2206 |
| 2205 mouse_locked_ = false; | 2207 mouse_locked_ = false; |
| 2206 | 2208 |
| 2207 #if !defined(OS_WIN) | 2209 #if !defined(OS_WIN) |
| 2208 window_->ReleaseCapture(); | 2210 window_->ReleaseCapture(); |
| 2209 #endif | 2211 #endif |
| 2210 window_->MoveCursorTo(unlocked_mouse_position_); | 2212 window_->MoveCursorTo(unlocked_mouse_position_); |
| 2211 aura::client::CursorClient* cursor_client = | 2213 aura::client::CursorClient* cursor_client = |
| 2212 aura::client::GetCursorClient(root_window); | 2214 aura::client::GetCursorClient(dispatcher); |
| 2213 if (cursor_client) { | 2215 if (cursor_client) { |
| 2214 cursor_client->UnlockCursor(); | 2216 cursor_client->UnlockCursor(); |
| 2215 cursor_client->ShowCursor(); | 2217 cursor_client->ShowCursor(); |
| 2216 } | 2218 } |
| 2217 | 2219 |
| 2218 if (aura::client::GetTooltipClient(root_window)) | 2220 if (aura::client::GetTooltipClient(dispatcher)) |
| 2219 aura::client::GetTooltipClient(root_window)->SetTooltipsEnabled(true); | 2221 aura::client::GetTooltipClient(dispatcher)->SetTooltipsEnabled(true); |
| 2220 | 2222 |
| 2221 host_->LostMouseLock(); | 2223 host_->LostMouseLock(); |
| 2224 dispatcher->UnConfineCursor(); |
| 2222 } | 2225 } |
| 2223 | 2226 |
| 2224 //////////////////////////////////////////////////////////////////////////////// | 2227 //////////////////////////////////////////////////////////////////////////////// |
| 2225 // RenderWidgetHostViewAura, ui::TextInputClient implementation: | 2228 // RenderWidgetHostViewAura, ui::TextInputClient implementation: |
| 2226 void RenderWidgetHostViewAura::SetCompositionText( | 2229 void RenderWidgetHostViewAura::SetCompositionText( |
| 2227 const ui::CompositionText& composition) { | 2230 const ui::CompositionText& composition) { |
| 2228 if (!host_) | 2231 if (!host_) |
| 2229 return; | 2232 return; |
| 2230 | 2233 |
| 2231 // ui::CompositionUnderline should be identical to | 2234 // 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()); | 2726 DCHECK(!cursor_client || !cursor_client->IsCursorVisible()); |
| 2724 | 2727 |
| 2725 if (event->type() == ui::ET_MOUSEWHEEL) { | 2728 if (event->type() == ui::ET_MOUSEWHEEL) { |
| 2726 WebKit::WebMouseWheelEvent mouse_wheel_event = | 2729 WebKit::WebMouseWheelEvent mouse_wheel_event = |
| 2727 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event)); | 2730 MakeWebMouseWheelEvent(static_cast<ui::MouseWheelEvent*>(event)); |
| 2728 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) | 2731 if (mouse_wheel_event.deltaX != 0 || mouse_wheel_event.deltaY != 0) |
| 2729 host_->ForwardWheelEvent(mouse_wheel_event); | 2732 host_->ForwardWheelEvent(mouse_wheel_event); |
| 2730 return; | 2733 return; |
| 2731 } | 2734 } |
| 2732 | 2735 |
| 2736 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); |
| 2737 |
| 2738 // If we receive non client mouse messages while we are in the locked state |
| 2739 // it probably means that the mouse left the borders of our window and |
| 2740 // needs to be moved back to the center. |
| 2741 if (event->flags() & ui::EF_IS_NON_CLIENT) { |
| 2742 synthetic_move_sent_ = true; |
| 2743 window_->MoveCursorTo(center); |
| 2744 return; |
| 2745 } |
| 2746 |
| 2733 WebKit::WebMouseEvent mouse_event = MakeWebMouseEvent(event); | 2747 WebKit::WebMouseEvent mouse_event = MakeWebMouseEvent(event); |
| 2734 gfx::Point center(gfx::Rect(window_->bounds().size()).CenterPoint()); | |
| 2735 | 2748 |
| 2736 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || | 2749 bool is_move_to_center_event = (event->type() == ui::ET_MOUSE_MOVED || |
| 2737 event->type() == ui::ET_MOUSE_DRAGGED) && | 2750 event->type() == ui::ET_MOUSE_DRAGGED) && |
| 2738 mouse_event.x == center.x() && mouse_event.y == center.y(); | 2751 mouse_event.x == center.x() && mouse_event.y == center.y(); |
| 2739 | 2752 |
| 2740 ModifyEventMovementAndCoords(&mouse_event); | 2753 ModifyEventMovementAndCoords(&mouse_event); |
| 2741 | 2754 |
| 2742 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; | 2755 bool should_not_forward = is_move_to_center_event && synthetic_move_sent_; |
| 2743 if (should_not_forward) { | 2756 if (should_not_forward) { |
| 2744 synthetic_move_sent_ = false; | 2757 synthetic_move_sent_ = false; |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3425 RenderWidgetHost* widget) { | 3438 RenderWidgetHost* widget) { |
| 3426 return new RenderWidgetHostViewAura(widget); | 3439 return new RenderWidgetHostViewAura(widget); |
| 3427 } | 3440 } |
| 3428 | 3441 |
| 3429 // static | 3442 // static |
| 3430 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3443 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3431 GetScreenInfoForWindow(results, NULL); | 3444 GetScreenInfoForWindow(results, NULL); |
| 3432 } | 3445 } |
| 3433 | 3446 |
| 3434 } // namespace content | 3447 } // namespace content |
| OLD | NEW |