| 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 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 old_child->popup_parent_host_view_ = NULL; | 670 old_child->popup_parent_host_view_ = NULL; |
| 671 } | 671 } |
| 672 popup_parent_host_view_->popup_child_host_view_ = this; | 672 popup_parent_host_view_->popup_child_host_view_ = this; |
| 673 window_->SetType(aura::client::WINDOW_TYPE_MENU); | 673 window_->SetType(aura::client::WINDOW_TYPE_MENU); |
| 674 window_->Init(ui::LAYER_TEXTURED); | 674 window_->Init(ui::LAYER_TEXTURED); |
| 675 window_->SetName("RenderWidgetHostViewAura"); | 675 window_->SetName("RenderWidgetHostViewAura"); |
| 676 | 676 |
| 677 aura::RootWindow* root = popup_parent_host_view_->window_->GetRootWindow(); | 677 aura::RootWindow* root = popup_parent_host_view_->window_->GetRootWindow(); |
| 678 window_->SetDefaultParentByRootWindow(root, bounds_in_screen); | 678 window_->SetDefaultParentByRootWindow(root, bounds_in_screen); |
| 679 | 679 |
| 680 // TODO(erg): While I could make sure details of the StackingClient are | 680 SetBounds(bounds_in_screen); |
| 681 // hidden behind aura, hiding the details of the ScreenPositionClient will | |
| 682 // take another effort. | |
| 683 aura::client::ScreenPositionClient* screen_position_client = | |
| 684 aura::client::GetScreenPositionClient(root); | |
| 685 gfx::Point origin_in_parent(bounds_in_screen.origin()); | |
| 686 if (screen_position_client) { | |
| 687 screen_position_client->ConvertPointFromScreen( | |
| 688 window_->parent(), &origin_in_parent); | |
| 689 } | |
| 690 SetBounds(gfx::Rect(origin_in_parent, bounds_in_screen.size())); | |
| 691 Show(); | 681 Show(); |
| 692 } | 682 } |
| 693 | 683 |
| 694 void RenderWidgetHostViewAura::InitAsFullscreen( | 684 void RenderWidgetHostViewAura::InitAsFullscreen( |
| 695 RenderWidgetHostView* reference_host_view) { | 685 RenderWidgetHostView* reference_host_view) { |
| 696 is_fullscreen_ = true; | 686 is_fullscreen_ = true; |
| 697 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); | 687 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); |
| 698 window_->Init(ui::LAYER_TEXTURED); | 688 window_->Init(ui::LAYER_TEXTURED); |
| 699 window_->SetName("RenderWidgetHostViewAura"); | 689 window_->SetName("RenderWidgetHostViewAura"); |
| 700 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 690 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 701 | 691 |
| 702 aura::RootWindow* parent = NULL; | 692 aura::RootWindow* parent = NULL; |
| 703 gfx::Rect bounds; | 693 gfx::Rect bounds; |
| 704 if (reference_host_view) { | 694 if (reference_host_view) { |
| 705 aura::Window* reference_window = | 695 aura::Window* reference_window = |
| 706 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; | 696 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; |
| 707 if (reference_window) { | 697 if (reference_window) { |
| 708 host_tracker_.reset(new aura::WindowTracker); | 698 host_tracker_.reset(new aura::WindowTracker); |
| 709 host_tracker_->Add(reference_window); | 699 host_tracker_->Add(reference_window); |
| 710 } | 700 } |
| 711 gfx::Display display = gfx::Screen::GetScreenFor(window_)-> | 701 gfx::Display display = gfx::Screen::GetScreenFor(window_)-> |
| 712 GetDisplayNearestWindow(reference_window); | 702 GetDisplayNearestWindow(reference_window); |
| 713 parent = reference_window->GetRootWindow(); | 703 parent = reference_window->GetRootWindow(); |
| 714 bounds = display.bounds(); | 704 bounds = display.bounds(); |
| 715 } | 705 } |
| 706 |
| 716 window_->SetDefaultParentByRootWindow(parent, bounds); | 707 window_->SetDefaultParentByRootWindow(parent, bounds); |
| 717 Show(); | 708 Show(); |
| 718 Focus(); | 709 Focus(); |
| 719 } | 710 } |
| 720 | 711 |
| 721 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const { | 712 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const { |
| 722 return host_; | 713 return host_; |
| 723 } | 714 } |
| 724 | 715 |
| 725 void RenderWidgetHostViewAura::WasShown() { | 716 void RenderWidgetHostViewAura::WasShown() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 756 if (root_window) { | 747 if (root_window) { |
| 757 HWND parent = root_window->GetAcceleratedWidget(); | 748 HWND parent = root_window->GetAcceleratedWidget(); |
| 758 LPARAM lparam = reinterpret_cast<LPARAM>(this); | 749 LPARAM lparam = reinterpret_cast<LPARAM>(this); |
| 759 | 750 |
| 760 EnumChildWindows(parent, HideWindowsCallback, lparam); | 751 EnumChildWindows(parent, HideWindowsCallback, lparam); |
| 761 } | 752 } |
| 762 #endif | 753 #endif |
| 763 } | 754 } |
| 764 | 755 |
| 765 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { | 756 void RenderWidgetHostViewAura::SetSize(const gfx::Size& size) { |
| 766 SetBounds(gfx::Rect(window_->bounds().origin(), size)); | 757 // For a set size operation, we don't care what coordinate system the origin |
| 758 // of the window is stored in, it's only important to make sure the origin |
| 759 // remains constant after the operation. |
| 760 InternalSetBounds(gfx::Rect(window_->bounds().origin(), size)); |
| 767 } | 761 } |
| 768 | 762 |
| 769 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { | 763 void RenderWidgetHostViewAura::SetBounds(const gfx::Rect& rect) { |
| 770 if (HasDisplayPropertyChanged(window_)) | 764 // RenderWidgetHostViewAura::SetBounds() takes screen coordinates, but |
| 771 host_->InvalidateScreenInfo(); | 765 // Window::SetBounds() takes parent coordinates, so we do the conversion here. |
| 766 aura::RootWindow* root = window_->GetRootWindow(); |
| 767 aura::client::ScreenPositionClient* screen_position_client = |
| 768 aura::client::GetScreenPositionClient(root); |
| 769 gfx::Point origin_in_parent(rect.origin()); |
| 770 if (screen_position_client) { |
| 771 screen_position_client->ConvertPointFromScreen( |
| 772 window_->parent(), &origin_in_parent); |
| 773 } |
| 772 | 774 |
| 773 window_->SetBounds(rect); | 775 InternalSetBounds(gfx::Rect(origin_in_parent, rect.size())); |
| 774 host_->WasResized(); | |
| 775 MaybeCreateResizeLock(); | |
| 776 if (touch_editing_client_) { | |
| 777 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_, | |
| 778 selection_focus_rect_); | |
| 779 } | |
| 780 } | |
| 781 | |
| 782 void RenderWidgetHostViewAura::MaybeCreateResizeLock() { | |
| 783 gfx::Size desired_size = window_->bounds().size(); | |
| 784 if (!host_->should_auto_resize() && | |
| 785 !resize_lock_.get() && | |
| 786 desired_size != current_frame_size_ && | |
| 787 host_->is_accelerated_compositing_active()) { | |
| 788 aura::RootWindow* root_window = window_->GetRootWindow(); | |
| 789 ui::Compositor* compositor = root_window ? | |
| 790 root_window->compositor() : NULL; | |
| 791 if (root_window && compositor) { | |
| 792 // Listen to changes in the compositor lock state. | |
| 793 if (!compositor->HasObserver(this)) | |
| 794 compositor->AddObserver(this); | |
| 795 | |
| 796 // On Windows while resizing, the the resize locks makes us mis-paint a white | |
| 797 // vertical strip (including the non-client area) if the content composition is | |
| 798 // lagging the UI composition. So here we disable the throttling so that the UI | |
| 799 // bits can draw ahead of the content thereby reducing the amount of whiteout. | |
| 800 // Because this causes the content to be drawn at wrong sizes while resizing | |
| 801 // we compensate by blocking the UI thread in Compositor::Draw() by issuing a | |
| 802 // FinishAllRendering() if we are resizing. | |
| 803 #if !defined (OS_WIN) | |
| 804 bool defer_compositor_lock = | |
| 805 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || | |
| 806 can_lock_compositor_ == NO_PENDING_COMMIT; | |
| 807 | |
| 808 if (can_lock_compositor_ == YES) | |
| 809 can_lock_compositor_ = YES_DID_LOCK; | |
| 810 | |
| 811 resize_lock_.reset(new ResizeLock(root_window, desired_size, | |
| 812 defer_compositor_lock)); | |
| 813 #endif | |
| 814 } | |
| 815 } | |
| 816 } | 776 } |
| 817 | 777 |
| 818 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { | 778 gfx::NativeView RenderWidgetHostViewAura::GetNativeView() const { |
| 819 return window_; | 779 return window_; |
| 820 } | 780 } |
| 821 | 781 |
| 822 gfx::NativeViewId RenderWidgetHostViewAura::GetNativeViewId() const { | 782 gfx::NativeViewId RenderWidgetHostViewAura::GetNativeViewId() const { |
| 823 #if defined(OS_WIN) | 783 #if defined(OS_WIN) |
| 824 aura::RootWindow* root_window = window_->GetRootWindow(); | 784 aura::RootWindow* root_window = window_->GetRootWindow(); |
| 825 if (root_window) { | 785 if (root_window) { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 void RenderWidgetHostViewAura::CopyFromCompositingSurface( | 1133 void RenderWidgetHostViewAura::CopyFromCompositingSurface( |
| 1174 const gfx::Rect& src_subrect, | 1134 const gfx::Rect& src_subrect, |
| 1175 const gfx::Size& dst_size, | 1135 const gfx::Size& dst_size, |
| 1176 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 1136 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
| 1177 if (!window_->layer()->has_external_content()) { | 1137 if (!window_->layer()->has_external_content()) { |
| 1178 callback.Run(false, SkBitmap()); | 1138 callback.Run(false, SkBitmap()); |
| 1179 return; | 1139 return; |
| 1180 } | 1140 } |
| 1181 | 1141 |
| 1182 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); | 1142 const gfx::Size& dst_size_in_pixel = ConvertViewSizeToPixel(this, dst_size); |
| 1143 |
| 1183 scoped_ptr<cc::CopyOutputRequest> request = | 1144 scoped_ptr<cc::CopyOutputRequest> request = |
| 1184 cc::CopyOutputRequest::CreateRequest(base::Bind( | 1145 cc::CopyOutputRequest::CreateRequest(base::Bind( |
| 1185 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResult, | 1146 &RenderWidgetHostViewAura::CopyFromCompositingSurfaceHasResult, |
| 1186 dst_size_in_pixel, | 1147 dst_size_in_pixel, |
| 1187 callback)); | 1148 callback)); |
| 1188 gfx::Rect src_subrect_in_pixel = | 1149 gfx::Rect src_subrect_in_pixel = |
| 1189 ConvertRectToPixel(current_device_scale_factor_, src_subrect); | 1150 ConvertRectToPixel(current_device_scale_factor_, src_subrect); |
| 1190 request->set_area(src_subrect_in_pixel); | 1151 request->set_area(src_subrect_in_pixel); |
| 1191 window_->layer()->RequestCopyOfOutput(request.Pass()); | 1152 window_->layer()->RequestCopyOfOutput(request.Pass()); |
| 1192 } | 1153 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 | 1206 |
| 1246 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const { | 1207 bool RenderWidgetHostViewAura::ShouldSkipFrame(gfx::Size size_in_dip) const { |
| 1247 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || | 1208 if (can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
| 1248 can_lock_compositor_ == NO_PENDING_COMMIT || | 1209 can_lock_compositor_ == NO_PENDING_COMMIT || |
| 1249 !resize_lock_.get()) | 1210 !resize_lock_.get()) |
| 1250 return false; | 1211 return false; |
| 1251 | 1212 |
| 1252 return size_in_dip != resize_lock_->expected_size(); | 1213 return size_in_dip != resize_lock_->expected_size(); |
| 1253 } | 1214 } |
| 1254 | 1215 |
| 1216 void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) { |
| 1217 if (HasDisplayPropertyChanged(window_)) |
| 1218 host_->InvalidateScreenInfo(); |
| 1219 |
| 1220 window_->SetBounds(rect); |
| 1221 host_->WasResized(); |
| 1222 MaybeCreateResizeLock(); |
| 1223 if (touch_editing_client_) { |
| 1224 touch_editing_client_->OnSelectionOrCursorChanged(selection_anchor_rect_, |
| 1225 selection_focus_rect_); |
| 1226 } |
| 1227 } |
| 1228 |
| 1229 void RenderWidgetHostViewAura::MaybeCreateResizeLock() { |
| 1230 gfx::Size desired_size = window_->bounds().size(); |
| 1231 if (!host_->should_auto_resize() && |
| 1232 !resize_lock_.get() && |
| 1233 desired_size != current_frame_size_ && |
| 1234 host_->is_accelerated_compositing_active()) { |
| 1235 aura::RootWindow* root_window = window_->GetRootWindow(); |
| 1236 ui::Compositor* compositor = root_window ? |
| 1237 root_window->compositor() : NULL; |
| 1238 if (root_window && compositor) { |
| 1239 // Listen to changes in the compositor lock state. |
| 1240 if (!compositor->HasObserver(this)) |
| 1241 compositor->AddObserver(this); |
| 1242 |
| 1243 // On Windows while resizing, the the resize locks makes us mis-paint a white |
| 1244 // vertical strip (including the non-client area) if the content composition is |
| 1245 // lagging the UI composition. So here we disable the throttling so that the UI |
| 1246 // bits can draw ahead of the content thereby reducing the amount of whiteout. |
| 1247 // Because this causes the content to be drawn at wrong sizes while resizing |
| 1248 // we compensate by blocking the UI thread in Compositor::Draw() by issuing a |
| 1249 // FinishAllRendering() if we are resizing. |
| 1250 #if !defined (OS_WIN) |
| 1251 bool defer_compositor_lock = |
| 1252 can_lock_compositor_ == NO_PENDING_RENDERER_FRAME || |
| 1253 can_lock_compositor_ == NO_PENDING_COMMIT; |
| 1254 |
| 1255 if (can_lock_compositor_ == YES) |
| 1256 can_lock_compositor_ = YES_DID_LOCK; |
| 1257 |
| 1258 resize_lock_.reset(new ResizeLock(root_window, desired_size, |
| 1259 defer_compositor_lock)); |
| 1260 #endif |
| 1261 } |
| 1262 } |
| 1263 } |
| 1264 |
| 1255 void RenderWidgetHostViewAura::CheckResizeLock() { | 1265 void RenderWidgetHostViewAura::CheckResizeLock() { |
| 1256 if (!resize_lock_ || resize_lock_->expected_size() != current_frame_size_) | 1266 if (!resize_lock_ || resize_lock_->expected_size() != current_frame_size_) |
| 1257 return; | 1267 return; |
| 1258 | 1268 |
| 1259 // Since we got the size we were looking for, unlock the compositor. But delay | 1269 // Since we got the size we were looking for, unlock the compositor. But delay |
| 1260 // the release of the lock until we've kicked a frame with the new texture, to | 1270 // the release of the lock until we've kicked a frame with the new texture, to |
| 1261 // avoid resizing the UI before we have a chance to draw a "good" frame. | 1271 // avoid resizing the UI before we have a chance to draw a "good" frame. |
| 1262 resize_lock_->UnlockCompositor(); | 1272 resize_lock_->UnlockCompositor(); |
| 1263 ui::Compositor* compositor = GetCompositor(); | 1273 ui::Compositor* compositor = GetCompositor(); |
| 1264 if (compositor) { | 1274 if (compositor) { |
| (...skipping 1879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3144 RenderWidgetHost* widget) { | 3154 RenderWidgetHost* widget) { |
| 3145 return new RenderWidgetHostViewAura(widget); | 3155 return new RenderWidgetHostViewAura(widget); |
| 3146 } | 3156 } |
| 3147 | 3157 |
| 3148 // static | 3158 // static |
| 3149 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { | 3159 void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 3150 GetScreenInfoForWindow(results, NULL); | 3160 GetScreenInfoForWindow(results, NULL); |
| 3151 } | 3161 } |
| 3152 | 3162 |
| 3153 } // namespace content | 3163 } // namespace content |
| OLD | NEW |