| 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/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 } | 961 } |
| 962 | 962 |
| 963 void RenderWidgetHostViewAura::EndFrameSubscription() { | 963 void RenderWidgetHostViewAura::EndFrameSubscription() { |
| 964 delegated_frame_host_->EndFrameSubscription(); | 964 delegated_frame_host_->EndFrameSubscription(); |
| 965 } | 965 } |
| 966 | 966 |
| 967 void RenderWidgetHostViewAura::AcceleratedSurfaceInitialized(int host_id, | 967 void RenderWidgetHostViewAura::AcceleratedSurfaceInitialized(int host_id, |
| 968 int route_id) { | 968 int route_id) { |
| 969 } | 969 } |
| 970 | 970 |
| 971 void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() { | |
| 972 // The top left corner of our view in window coordinates might not land on a | |
| 973 // device pixel boundary if we have a non-integer device scale. In that case, | |
| 974 // to avoid the web contents area looking blurry we translate the web contents | |
| 975 // in the +x, +y direction to land on the nearest pixel boundary. This may | |
| 976 // cause the bottom and right edges to be clipped slightly, but that's ok. | |
| 977 gfx::Point view_offset_dips = window_->GetBoundsInRootWindow().origin(); | |
| 978 gfx::PointF view_offset = view_offset_dips; | |
| 979 view_offset.Scale(current_device_scale_factor_); | |
| 980 gfx::PointF view_offset_snapped(std::ceil(view_offset.x()), | |
| 981 std::ceil(view_offset.y())); | |
| 982 | |
| 983 gfx::Vector2dF fudge = view_offset_snapped - view_offset; | |
| 984 fudge.Scale(1.0 / current_device_scale_factor_); | |
| 985 GetLayer()->SetSubpixelPositionOffset(fudge); | |
| 986 } | |
| 987 | |
| 988 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { | |
| 989 if (HasDisplayPropertyChanged(window_)) | |
| 990 host_->InvalidateScreenInfo(); | |
| 991 | |
| 992 SnapToPhysicalPixelBoundary(); | |
| 993 // Don't recursively call SetBounds if this bounds update is the result of | |
| 994 // a Window::SetBoundsInternal call. | |
| 995 if (!in_bounds_changed_) | |
| 996 window_->SetBounds(rect); | |
| 997 host_->WasResized(); | |
| 998 delegated_frame_host_->WasResized(); | |
| 999 if (touch_editing_client_) { | |
| 1000 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_, | |
| 1001 selection_focus_rect_); | |
| 1002 } | |
| 1003 #if defined(OS_WIN) | |
| 1004 // Create the legacy dummy window which corresponds to the bounds of the | |
| 1005 // webcontents. This will be passed as the container window for windowless | |
| 1006 // plugins. | |
| 1007 // Plugins like Flash assume the container window which is returned via the | |
| 1008 // NPNVnetscapeWindow property corresponds to the bounds of the webpage. | |
| 1009 // This is not true in Aura where we have only HWND which is the main Aura | |
| 1010 // window. If we return this window to plugins like Flash then it causes the | |
| 1011 // coordinate translations done by these plugins to break. | |
| 1012 // Additonally the legacy dummy window is needed for accessibility and for | |
| 1013 // scrolling to work in legacy drivers for trackpoints/trackpads, etc. | |
| 1014 if (!legacy_window_destroyed_ && GetNativeViewId()) { | |
| 1015 if (!legacy_render_widget_host_HWND_) { | |
| 1016 legacy_render_widget_host_HWND_ = LegacyRenderWidgetHostHWND::Create( | |
| 1017 reinterpret_cast<HWND>(GetNativeViewId())); | |
| 1018 } | |
| 1019 if (legacy_render_widget_host_HWND_) { | |
| 1020 legacy_render_widget_host_HWND_->set_host(this); | |
| 1021 legacy_render_widget_host_HWND_->SetBounds( | |
| 1022 window_->GetBoundsInRootWindow()); | |
| 1023 // There are cases where the parent window is created, made visible and | |
| 1024 // the associated RenderWidget is also visible before the | |
| 1025 // LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown | |
| 1026 // here. | |
| 1027 if (!host_->is_hidden()) | |
| 1028 legacy_render_widget_host_HWND_->Show(); | |
| 1029 | |
| 1030 BrowserAccessibilityManagerWin* manager = | |
| 1031 static_cast<BrowserAccessibilityManagerWin*>( | |
| 1032 GetBrowserAccessibilityManager()); | |
| 1033 if (manager) | |
| 1034 manager->SetAccessibleHWND(legacy_render_widget_host_HWND_); | |
| 1035 } | |
| 1036 } | |
| 1037 | |
| 1038 if (mouse_locked_) | |
| 1039 UpdateMouseLockRegion(); | |
| 1040 #endif | |
| 1041 } | |
| 1042 | |
| 1043 #if defined(OS_WIN) | 971 #if defined(OS_WIN) |
| 1044 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const { | 972 bool RenderWidgetHostViewAura::UsesNativeWindowFrame() const { |
| 1045 return (legacy_render_widget_host_HWND_ != NULL); | 973 return (legacy_render_widget_host_HWND_ != NULL); |
| 1046 } | 974 } |
| 1047 | 975 |
| 1048 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects( | 976 void RenderWidgetHostViewAura::UpdateConstrainedWindowRects( |
| 1049 const std::vector<gfx::Rect>& rects) { | 977 const std::vector<gfx::Rect>& rects) { |
| 1050 // Check this before setting constrained_rects_, so that next time they're set | 978 // Check this before setting constrained_rects_, so that next time they're set |
| 1051 // and we have a root window we don't early return. | 979 // and we have a root window we don't early return. |
| 1052 if (!window_->GetHost()) | 980 if (!window_->GetHost()) |
| (...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2307 host_->SendCursorVisibilityState(is_visible); | 2235 host_->SendCursorVisibilityState(is_visible); |
| 2308 } | 2236 } |
| 2309 | 2237 |
| 2310 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) { | 2238 void RenderWidgetHostViewAura::SetOverscrollControllerEnabled(bool enabled) { |
| 2311 if (!enabled) | 2239 if (!enabled) |
| 2312 overscroll_controller_.reset(); | 2240 overscroll_controller_.reset(); |
| 2313 else if (!overscroll_controller_) | 2241 else if (!overscroll_controller_) |
| 2314 overscroll_controller_.reset(new OverscrollController()); | 2242 overscroll_controller_.reset(new OverscrollController()); |
| 2315 } | 2243 } |
| 2316 | 2244 |
| 2245 void RenderWidgetHostViewAura::SnapToPhysicalPixelBoundary() { |
| 2246 // The top left corner of our view in window coordinates might not land on a |
| 2247 // device pixel boundary if we have a non-integer device scale. In that case, |
| 2248 // to avoid the web contents area looking blurry we translate the web contents |
| 2249 // in the +x, +y direction to land on the nearest pixel boundary. This may |
| 2250 // cause the bottom and right edges to be clipped slightly, but that's ok. |
| 2251 gfx::Point view_offset_dips = window_->GetBoundsInRootWindow().origin(); |
| 2252 gfx::PointF view_offset = view_offset_dips; |
| 2253 view_offset.Scale(current_device_scale_factor_); |
| 2254 gfx::PointF view_offset_snapped(std::ceil(view_offset.x()), |
| 2255 std::ceil(view_offset.y())); |
| 2256 |
| 2257 gfx::Vector2dF fudge = view_offset_snapped - view_offset; |
| 2258 fudge.Scale(1.0 / current_device_scale_factor_); |
| 2259 GetLayer()->SetSubpixelPositionOffset(fudge); |
| 2260 } |
| 2261 |
| 2262 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { |
| 2263 if (HasDisplayPropertyChanged(window_)) |
| 2264 host_->InvalidateScreenInfo(); |
| 2265 |
| 2266 SnapToPhysicalPixelBoundary(); |
| 2267 // Don't recursively call SetBounds if this bounds update is the result of |
| 2268 // a Window::SetBoundsInternal call. |
| 2269 if (!in_bounds_changed_) |
| 2270 window_->SetBounds(rect); |
| 2271 host_->WasResized(); |
| 2272 delegated_frame_host_->WasResized(); |
| 2273 if (touch_editing_client_) { |
| 2274 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_, |
| 2275 selection_focus_rect_); |
| 2276 } |
| 2277 #if defined(OS_WIN) |
| 2278 // Create the legacy dummy window which corresponds to the bounds of the |
| 2279 // webcontents. This will be passed as the container window for windowless |
| 2280 // plugins. |
| 2281 // Plugins like Flash assume the container window which is returned via the |
| 2282 // NPNVnetscapeWindow property corresponds to the bounds of the webpage. |
| 2283 // This is not true in Aura where we have only HWND which is the main Aura |
| 2284 // window. If we return this window to plugins like Flash then it causes the |
| 2285 // coordinate translations done by these plugins to break. |
| 2286 // Additonally the legacy dummy window is needed for accessibility and for |
| 2287 // scrolling to work in legacy drivers for trackpoints/trackpads, etc. |
| 2288 if (!legacy_window_destroyed_ && GetNativeViewId()) { |
| 2289 if (!legacy_render_widget_host_HWND_) { |
| 2290 legacy_render_widget_host_HWND_ = LegacyRenderWidgetHostHWND::Create( |
| 2291 reinterpret_cast<HWND>(GetNativeViewId())); |
| 2292 } |
| 2293 if (legacy_render_widget_host_HWND_) { |
| 2294 legacy_render_widget_host_HWND_->set_host(this); |
| 2295 legacy_render_widget_host_HWND_->SetBounds( |
| 2296 window_->GetBoundsInRootWindow()); |
| 2297 // There are cases where the parent window is created, made visible and |
| 2298 // the associated RenderWidget is also visible before the |
| 2299 // LegacyRenderWidgetHostHWND instace is created. Ensure that it is shown |
| 2300 // here. |
| 2301 if (!host_->is_hidden()) |
| 2302 legacy_render_widget_host_HWND_->Show(); |
| 2303 |
| 2304 BrowserAccessibilityManagerWin* manager = |
| 2305 static_cast<BrowserAccessibilityManagerWin*>( |
| 2306 GetBrowserAccessibilityManager()); |
| 2307 if (manager) |
| 2308 manager->SetAccessibleHWND(legacy_render_widget_host_HWND_); |
| 2309 } |
| 2310 } |
| 2311 |
| 2312 if (mouse_locked_) |
| 2313 UpdateMouseLockRegion(); |
| 2314 #endif |
| 2315 } |
| 2316 |
| 2317 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip( | 2317 void RenderWidgetHostViewAura::SchedulePaintIfNotInClip( |
| 2318 const gfx::Rect& rect, | 2318 const gfx::Rect& rect, |
| 2319 const gfx::Rect& clip) { | 2319 const gfx::Rect& clip) { |
| 2320 if (!clip.IsEmpty()) { | 2320 if (!clip.IsEmpty()) { |
| 2321 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); | 2321 gfx::Rect to_paint = gfx::SubtractRects(rect, clip); |
| 2322 if (!to_paint.IsEmpty()) | 2322 if (!to_paint.IsEmpty()) |
| 2323 window_->SchedulePaintInRect(to_paint); | 2323 window_->SchedulePaintInRect(to_paint); |
| 2324 } else { | 2324 } else { |
| 2325 window_->SchedulePaintInRect(rect); | 2325 window_->SchedulePaintInRect(rect); |
| 2326 } | 2326 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2477 | 2477 |
| 2478 //////////////////////////////////////////////////////////////////////////////// | 2478 //////////////////////////////////////////////////////////////////////////////// |
| 2479 // RenderWidgetHostViewBase, public: | 2479 // RenderWidgetHostViewBase, public: |
| 2480 | 2480 |
| 2481 // static | 2481 // static |
| 2482 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2482 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2483 GetScreenInfoForWindow(results, NULL); | 2483 GetScreenInfoForWindow(results, NULL); |
| 2484 } | 2484 } |
| 2485 | 2485 |
| 2486 } // namespace content | 2486 } // namespace content |
| OLD | NEW |