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 // TODO(erg): While I could make sure details of the StackingClient are | 703 SetBounds(bounds_in_screen); |
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())); | |
714 Show(); | 704 Show(); |
715 } | 705 } |
716 | 706 |
717 void RenderWidgetHostViewAura::InitAsFullscreen( | 707 void RenderWidgetHostViewAura::InitAsFullscreen( |
718 RenderWidgetHostView* reference_host_view) { | 708 RenderWidgetHostView* reference_host_view) { |
719 is_fullscreen_ = true; | 709 is_fullscreen_ = true; |
720 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); | 710 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); |
721 window_->Init(ui::LAYER_TEXTURED); | 711 window_->Init(ui::LAYER_TEXTURED); |
722 window_->SetName("RenderWidgetHostViewAura"); | 712 window_->SetName("RenderWidgetHostViewAura"); |
723 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 713 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 if (root_window) { | 769 if (root_window) { |
780 HWND parent = root_window->GetAcceleratedWidget(); | 770 HWND parent = root_window->GetAcceleratedWidget(); |
781 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 771 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
782 | 772 |
783 EnumChildWindows(parent, HideWindowsCallback, lparam); | 773 EnumChildWindows(parent, HideWindowsCallback, lparam); |
784 } | 774 } |
785 #endif | 775 #endif |
786 } | 776 } |
787 | 777 |
788 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { | 778 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { |
789 SetBounds(gfx::Rect(window_->bounds().origin(), size)); | 779 // For a SetSize operation, we don't care what coordinate system the origin |
| 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)); |
790 } | 783 } |
791 | 784 |
792 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { | 785 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { |
793 if (HasDisplayPropertyChanged(window_)) | 786 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but |
794 host_->InvalidateScreenInfo(); | 787 // Window::SetBounds() takes parent coordinates, so do the conversion here. |
| 788 aura::RootWindow* root = window_->GetRootWindow(); |
| 789 aura::client::ScreenPositionClient* screen_position_client = |
| 790 aura::client::GetScreenPositionClient(root); |
| 791 gfx::Point origin_in_parent(rect.origin()); |
| 792 if (screen_position_client) { |
| 793 screen_position_client->ConvertPointFromScreen( |
| 794 window_->parent(), &origin_in_parent); |
| 795 } |
795 | 796 |
796 window_->SetBounds(rect); | 797 InternalSetBounds(gfx::Rect(origin_in_parent, rect.size())); |
797 host_->WasResized(); | |
798 MaybeCreateResizeLock(); | |
799 if (touch_editing_client_) { | |
800 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_, | |
801 selection_focus_rect_); | |
802 } | |
803 } | |
804 | |
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 } | |
839 } | 798 } |
840 | 799 |
841 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { | 800 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { |
842 return window_; | 801 return window_; |
843 } | 802 } |
844 | 803 |
845 gfx::NativeViewId RenderWidgetHostViewAura::GetNativeViewId() const { | 804 gfx::NativeViewId RenderWidgetHostViewAura::GetNativeViewId() const { |
846 #if defined(OS_WIN) | 805 #if defined(OS_WIN) |
847 aura::RootWindow* root_window = window_->GetRootWindow(); | 806 aura::RootWindow* root_window = window_->GetRootWindow(); |
848 if (root_window) { | 807 if (root_window) { |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 | 1232 |
1274 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const { | 1233 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const { |
1275 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || | 1234 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
1276 can_lock_compositor_ == NO_PENDING_COMMIT || | 1235 can_lock_compositor_ == NO_PENDING_COMMIT || |
1277 !resize_lock_.get()) | 1236 !resize_lock_.get()) |
1278 return false; | 1237 return false; |
1279 | 1238 |
1280 return size_in_dip != resize_lock_->expected_size(); | 1239 return size_in_dip != resize_lock_->expected_size(); |
1281 } | 1240 } |
1282 | 1241 |
| 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 |
1283 void RenderWidgetHostViewAura::CheckResizeLock() { | 1291 void RenderWidgetHostViewAura::CheckResizeLock() { |
1284 if (!resize_lock_ || resize_lock_->expected_size() != current_frame_size_) | 1292 if (!resize_lock_ || resize_lock_->expected_size() != current_frame_size_) |
1285 return; | 1293 return; |
1286 | 1294 |
1287 // Since we got the size we were looking for, unlock the compositor. But delay | 1295 // Since we got the size we were looking for, unlock the compositor. But delay |
1288 // the release of the lock until we've kicked a frame with the new texture, to | 1296 // the release of the lock until we've kicked a frame with the new texture, to |
1289 // avoid resizing the UI before we have a chance to draw a "good" frame. | 1297 // avoid resizing the UI before we have a chance to draw a "good" frame. |
1290 resize_lock_->UnlockCompositor(); | 1298 resize_lock_->UnlockCompositor(); |
1291 ui::Compositor* compositor = GetCompositor(); | 1299 ui::Compositor* compositor = GetCompositor(); |
1292 if (compositor) { | 1300 if (compositor) { |
(...skipping 1948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3241 RenderWidgetHost* widget) { | 3249 RenderWidgetHost* widget) { |
3242 return new RenderWidgetHostViewAura(widget); | 3250 return new RenderWidgetHostViewAura(widget); |
3243 } | 3251 } |
3244 | 3252 |
3245 // static | 3253 // static |
3246 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3254 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
3247 GetScreenInfoForWindow(results, NULL); | 3255 GetScreenInfoForWindow(results, NULL); |
3248 } | 3256 } |
3249 | 3257 |
3250 } // namespace content | 3258 } // namespace content |
OLD | NEW |