| 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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 old_child->popup_parent_host_view_ = NULL; | 693 old_child->popup_parent_host_view_ = NULL; |
| 694 } | 694 } |
| 695 popup_parent_host_view_->popup_child_host_view_ = this; | 695 popup_parent_host_view_->popup_child_host_view_ = this; |
| 696 window_->SetType(aura::client::WINDOW_TYPE_MENU); | 696 window_->SetType(aura::client::WINDOW_TYPE_MENU); |
| 697 window_->Init(ui::LAYER_TEXTURED); | 697 window_->Init(ui::LAYER_TEXTURED); |
| 698 window_->SetName("RenderWidgetHostViewAura"); | 698 window_->SetName("RenderWidgetHostViewAura"); |
| 699 | 699 |
| 700 aura::RootWindow* root = popup_parent_host_view_->window_->GetRootWindow(); | 700 aura::RootWindow* root = popup_parent_host_view_->window_->GetRootWindow(); |
| 701 window_->SetDefaultParentByRootWindow(root, bounds_in_screen); | 701 window_->SetDefaultParentByRootWindow(root, bounds_in_screen); |
| 702 | 702 |
| 703 SetBounds(bounds_in_screen); | 703 // TODO(erg): While I could make sure details of the StackingClient are |
| 704 // hidden behind aura, hiding the details of the ScreenPositionClient will |
| 705 // take another effort. |
| 706 aura::client::ScreenPositionClient* screen_position_client = |
| 707 aura::client::GetScreenPositionClient(root); |
| 708 gfx::Point origin_in_parent(bounds_in_screen.origin()); |
| 709 if (screen_position_client) { |
| 710 screen_position_client->ConvertPointFromScreen( |
| 711 window_->parent(), &origin_in_parent); |
| 712 } |
| 713 SetBounds(gfx::Rect(origin_in_parent, bounds_in_screen.size())); |
| 704 Show(); | 714 Show(); |
| 705 } | 715 } |
| 706 | 716 |
| 707 void RenderWidgetHostViewAura::InitAsFullscreen( | 717 void RenderWidgetHostViewAura::InitAsFullscreen( |
| 708 RenderWidgetHostView* reference_host_view) { | 718 RenderWidgetHostView* reference_host_view) { |
| 709 is_fullscreen_ = true; | 719 is_fullscreen_ = true; |
| 710 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); | 720 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); |
| 711 window_->Init(ui::LAYER_TEXTURED); | 721 window_->Init(ui::LAYER_TEXTURED); |
| 712 window_->SetName("RenderWidgetHostViewAura"); | 722 window_->SetName("RenderWidgetHostViewAura"); |
| 713 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 723 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 if (root_window) { | 779 if (root_window) { |
| 770 HWND parent = root_window->GetAcceleratedWidget(); | 780 HWND parent = root_window->GetAcceleratedWidget(); |
| 771 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 781 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
| 772 | 782 |
| 773 EnumChildWindows(parent, HideWindowsCallback, lparam); | 783 EnumChildWindows(parent, HideWindowsCallback, lparam); |
| 774 } | 784 } |
| 775 #endif | 785 #endif |
| 776 } | 786 } |
| 777 | 787 |
| 778 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { | 788 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { |
| 779 // For a SetSize operation, we don't care what coordinate system the origin | 789 SetBounds(gfx::Rect(window_->bounds().origin(), size)); |
| 780 // of the window is in, it's only important to make sure that the origin | |
| 781 // remains constant after the operation. | |
| 782 InternalSetBounds(gfx::Rect(window_->bounds().origin(), size)); | |
| 783 } | 790 } |
| 784 | 791 |
| 785 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { | 792 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { |
| 786 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but | 793 if (HasDisplayPropertyChanged(window_)) |
| 787 // Window::SetBounds() takes parent coordinates, so do the conversion here. | 794 host_->InvalidateScreenInfo(); |
| 788 aura::RootWindow* root = window_->GetRootWindow(); | 795 |
| 789 aura::client::ScreenPositionClient* screen_position_client = | 796 window_->SetBounds(rect); |
| 790 aura::client::GetScreenPositionClient(root); | 797 host_->WasResized(); |
| 791 gfx::Point origin_in_parent(rect.origin()); | 798 MaybeCreateResizeLock(); |
| 792 if (screen_position_client) { | 799 if (touch_editing_client_) { |
| 793 screen_position_client->ConvertPointFromScreen( | 800 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_, |
| 794 window_->parent(), &origin_in_parent); | 801 selection_focus_rect_); |
| 795 } | 802 } |
| 803 } |
| 796 | 804 |
| 797 InternalSetBounds(gfx::Rect(origin_in_parent, rect.size())); | 805 void RenderWidgetHostViewAura::MaybeCreateResizeLock() { |
| 806 gfx::Size desired_size = window_->bounds().size(); |
| 807 if (!host_->should_auto_resize() && |
| 808 !resize_lock_.get() && |
| 809 desired_size != current_frame_size_ && |
| 810 host_->is_accelerated_compositing_active()) { |
| 811 aura::RootWindow* root_window = window_->GetRootWindow(); |
| 812 ui::Compositor* compositor = root_window ? |
| 813 root_window->compositor() : NULL; |
| 814 if (root_window && compositor) { |
| 815 // Listen to changes in the compositor lock state. |
| 816 if (!compositor->HasObserver(this)) |
| 817 compositor->AddObserver(this); |
| 818 |
| 819 // On Windows while resizing, the the resize locks makes us mis-paint a white |
| 820 // vertical strip (including the non-client area) if the content composition is |
| 821 // lagging the UI composition. So here we disable the throttling so that the UI |
| 822 // bits can draw ahead of the content thereby reducing the amount of whiteout. |
| 823 // Because this causes the content to be drawn at wrong sizes while resizing |
| 824 // we compensate by blocking the UI thread in Compositor::Draw() by issuing a |
| 825 // FinishAllRendering() if we are resizing. |
| 826 #if !defined (OS_WIN) |
| 827 bool defer_compositor_lock = |
| 828 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
| 829 can_lock_compositor_ == NO_PENDING_COMMIT; |
| 830 |
| 831 if (can_lock_compositor_ == YES) |
| 832 can_lock_compositor_ = YES_DID_LOCK; |
| 833 |
| 834 resize_lock_.reset(new ResizeLock(root_window, desired_size, |
| 835 defer_compositor_lock)); |
| 836 #endif |
| 837 } |
| 838 } |
| 798 } | 839 } |
| 799 | 840 |
| 800 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { | 841 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { |
| 801 return window_; | 842 return window_; |
| 802 } | 843 } |
| 803 | 844 |
| 804 gfx::NativeViewId RenderWidgetHostViewAura::GetNativeViewId() const { | 845 gfx::NativeViewId RenderWidgetHostViewAura::GetNativeViewId() const { |
| 805 #if defined(OS_WIN) | 846 #if defined(OS_WIN) |
| 806 aura::RootWindow* root_window = window_->GetRootWindow(); | 847 aura::RootWindow* root_window = window_->GetRootWindow(); |
| 807 if (root_window) { | 848 if (root_window) { |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 | 1273 |
| 1233 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const { | 1274 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const { |
| 1234 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || | 1275 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
| 1235 can_lock_compositor_ == NO_PENDING_COMMIT || | 1276 can_lock_compositor_ == NO_PENDING_COMMIT || |
| 1236 !resize_lock_.get()) | 1277 !resize_lock_.get()) |
| 1237 return false; | 1278 return false; |
| 1238 | 1279 |
| 1239 return size_in_dip != resize_lock_->expected_size(); | 1280 return size_in_dip != resize_lock_->expected_size(); |
| 1240 } | 1281 } |
| 1241 | 1282 |
| 1242 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { | |
| 1243 if (HasDisplayPropertyChanged(window_)) | |
| 1244 host_->InvalidateScreenInfo(); | |
| 1245 | |
| 1246 window_->SetBounds(rect); | |
| 1247 host_->WasResized(); | |
| 1248 MaybeCreateResizeLock(); | |
| 1249 if (touch_editing_client_) { | |
| 1250 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_, | |
| 1251 selection_focus_rect_); | |
| 1252 } | |
| 1253 } | |
| 1254 | |
| 1255 void RenderWidgetHostViewAura::MaybeCreateResizeLock() { | |
| 1256 gfx::Size desired_size = window_->bounds().size(); | |
| 1257 if (!host_->should_auto_resize() && | |
| 1258 !resize_lock_.get() && | |
| 1259 desired_size != current_frame_size_ && | |
| 1260 host_->is_accelerated_compositing_active()) { | |
| 1261 aura::RootWindow* root_window = window_->GetRootWindow(); | |
| 1262 ui::Compositor* compositor = root_window ? | |
| 1263 root_window->compositor() : NULL; | |
| 1264 if (root_window && compositor) { | |
| 1265 // Listen to changes in the compositor lock state. | |
| 1266 if (!compositor->HasObserver(this)) | |
| 1267 compositor->AddObserver(this); | |
| 1268 | |
| 1269 // On Windows while resizing, the the resize locks makes us mis-paint a white | |
| 1270 // vertical strip (including the non-client area) if the content composition is | |
| 1271 // lagging the UI composition. So here we disable the throttling so that the UI | |
| 1272 // bits can draw ahead of the content thereby reducing the amount of whiteout. | |
| 1273 // Because this causes the content to be drawn at wrong sizes while resizing | |
| 1274 // we compensate by blocking the UI thread in Compositor::Draw() by issuing a | |
| 1275 // FinishAllRendering() if we are resizing. | |
| 1276 #if !defined (OS_WIN) | |
| 1277 bool defer_compositor_lock = | |
| 1278 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || | |
| 1279 can_lock_compositor_ == NO_PENDING_COMMIT; | |
| 1280 | |
| 1281 if (can_lock_compositor_ == YES) | |
| 1282 can_lock_compositor_ = YES_DID_LOCK; | |
| 1283 | |
| 1284 resize_lock_.reset(new ResizeLock(root_window, desired_size, | |
| 1285 defer_compositor_lock)); | |
| 1286 #endif | |
| 1287 } | |
| 1288 } | |
| 1289 } | |
| 1290 | |
| 1291 void RenderWidgetHostViewAura::CheckResizeLock() { | 1283 void RenderWidgetHostViewAura::CheckResizeLock() { |
| 1292 if (!resize_lock_ || resize_lock_->expected_size() != current_frame_size_) | 1284 if (!resize_lock_ || resize_lock_->expected_size() != current_frame_size_) |
| 1293 return; | 1285 return; |
| 1294 | 1286 |
| 1295 // Since we got the size we were looking for, unlock the compositor. But delay | 1287 // Since we got the size we were looking for, unlock the compositor. But delay |
| 1296 // the release of the lock until we've kicked a frame with the new texture, to | 1288 // the release of the lock until we've kicked a frame with the new texture, to |
| 1297 // avoid resizing the UI before we have a chance to draw a "good" frame. | 1289 // avoid resizing the UI before we have a chance to draw a "good" frame. |
| 1298 resize_lock_->UnlockCompositor(); | 1290 resize_lock_->UnlockCompositor(); |
| 1299 ui::Compositor* compositor = GetCompositor(); | 1291 ui::Compositor* compositor = GetCompositor(); |
| 1300 if (compositor) { | 1292 if (compositor) { |
| (...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3250 RenderWidgetHost* widget) { | 3242 RenderWidgetHost* widget) { |
| 3251 return new RenderWidgetHostViewAura(widget); | 3243 return new RenderWidgetHostViewAura(widget); |
| 3252 } | 3244 } |
| 3253 | 3245 |
| 3254 // static | 3246 // static |
| 3255 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3247 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3256 GetScreenInfoForWindow(results, NULL); | 3248 GetScreenInfoForWindow(results, NULL); |
| 3257 } | 3249 } |
| 3258 | 3250 |
| 3259 } // namespace content | 3251 } // namespace content |
| OLD | NEW |