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/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/browser/renderer_host/dip_util.h" | 10 #include "content/browser/renderer_host/dip_util.h" |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 491 |
492 private: | 492 private: |
493 friend class base::DeleteHelper<content::ShadowWindow>; | 493 friend class base::DeleteHelper<content::ShadowWindow>; |
494 | 494 |
495 virtual ~ShadowWindow() { | 495 virtual ~ShadowWindow() { |
496 if (window_) | 496 if (window_) |
497 window_->RemoveObserver(this); | 497 window_->RemoveObserver(this); |
498 } | 498 } |
499 | 499 |
500 void UpdateShadowBounds() { | 500 void UpdateShadowBounds() { |
501 if (!shadow_.get()) | 501 if (!shadow_) |
502 return; | 502 return; |
503 gfx::Rect bound; | 503 gfx::Rect bound; |
504 switch (edge_) { | 504 switch (edge_) { |
505 case SHADOW_LEFT: | 505 case SHADOW_LEFT: |
506 bound.SetRect(-kShadowThick, 0, kShadowThick, bounds().height()); | 506 bound.SetRect(-kShadowThick, 0, kShadowThick, bounds().height()); |
507 break; | 507 break; |
508 case SHADOW_RIGHT: | 508 case SHADOW_RIGHT: |
509 bound.SetRect(bounds().right(), 0, kShadowThick, bounds().height()); | 509 bound.SetRect(bounds().right(), 0, kShadowThick, bounds().height()); |
510 break; | 510 break; |
511 case SHADOW_TOP: | 511 case SHADOW_TOP: |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 window_observer_.reset(); | 889 window_observer_.reset(); |
890 #if defined(OS_WIN) | 890 #if defined(OS_WIN) |
891 child_window_observer_.reset(); | 891 child_window_observer_.reset(); |
892 #endif | 892 #endif |
893 // Window needs a valid delegate during its destructor, so we explicitly | 893 // Window needs a valid delegate during its destructor, so we explicitly |
894 // delete it here. | 894 // delete it here. |
895 window_.reset(); | 895 window_.reset(); |
896 } | 896 } |
897 | 897 |
898 void WebContentsViewAura::SetupOverlayWindowForTesting() { | 898 void WebContentsViewAura::SetupOverlayWindowForTesting() { |
899 if (navigation_overlay_.get()) | 899 if (navigation_overlay_) |
900 navigation_overlay_->SetupForTesting(); | 900 navigation_overlay_->SetupForTesting(); |
901 } | 901 } |
902 | 902 |
903 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { | 903 void WebContentsViewAura::SizeChangedCommon(const gfx::Size& size) { |
904 if (web_contents_->GetInterstitialPage()) | 904 if (web_contents_->GetInterstitialPage()) |
905 web_contents_->GetInterstitialPage()->SetSize(size); | 905 web_contents_->GetInterstitialPage()->SetSize(size); |
906 RenderWidgetHostView* rwhv = | 906 RenderWidgetHostView* rwhv = |
907 web_contents_->GetRenderWidgetHostView(); | 907 web_contents_->GetRenderWidgetHostView(); |
908 if (rwhv) | 908 if (rwhv) |
909 rwhv->SetSize(size); | 909 rwhv->SetSize(size); |
(...skipping 10 matching lines...) Expand all Loading... |
920 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), | 920 rvh->DragSourceEndedAt(client_loc.x(), client_loc.y(), screen_loc.x(), |
921 screen_loc.y(), ops); | 921 screen_loc.y(), ops); |
922 } | 922 } |
923 | 923 |
924 void WebContentsViewAura::PrepareOverscrollWindow() { | 924 void WebContentsViewAura::PrepareOverscrollWindow() { |
925 // If there is an existing |overscroll_window_| which is in the middle of an | 925 // If there is an existing |overscroll_window_| which is in the middle of an |
926 // animation, then destroying the window here causes the animation to be | 926 // animation, then destroying the window here causes the animation to be |
927 // completed immidiately, which triggers |OnImplicitAnimationsCompleted()| | 927 // completed immidiately, which triggers |OnImplicitAnimationsCompleted()| |
928 // callback, and that tries to reset |overscroll_window_| again, causing a | 928 // callback, and that tries to reset |overscroll_window_| again, causing a |
929 // double-free. So use a temporary variable here. | 929 // double-free. So use a temporary variable here. |
930 if (overscroll_window_.get()) { | 930 if (overscroll_window_) { |
931 base::AutoReset<OverscrollMode> reset_state(¤t_overscroll_gesture_, | 931 base::AutoReset<OverscrollMode> reset_state(¤t_overscroll_gesture_, |
932 current_overscroll_gesture_); | 932 current_overscroll_gesture_); |
933 scoped_ptr<aura::Window> reset_window(overscroll_window_.release()); | 933 scoped_ptr<aura::Window> reset_window(overscroll_window_.release()); |
934 } | 934 } |
935 | 935 |
936 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( | 936 OverscrollWindowDelegate* overscroll_delegate = new OverscrollWindowDelegate( |
937 web_contents_, | 937 web_contents_, |
938 current_overscroll_gesture_); | 938 current_overscroll_gesture_); |
939 overscroll_window_.reset(new aura::Window(overscroll_delegate)); | 939 overscroll_window_.reset(new aura::Window(overscroll_delegate)); |
940 overscroll_window_->SetType(aura::client::WINDOW_TYPE_CONTROL); | 940 overscroll_window_->SetType(aura::client::WINDOW_TYPE_CONTROL); |
941 overscroll_window_->SetTransparent(true); | 941 overscroll_window_->SetTransparent(true); |
942 overscroll_window_->Init(ui::LAYER_TEXTURED); | 942 overscroll_window_->Init(ui::LAYER_TEXTURED); |
943 overscroll_window_->layer()->SetMasksToBounds(true); | 943 overscroll_window_->layer()->SetMasksToBounds(true); |
944 overscroll_window_->SetName("OverscrollOverlay"); | 944 overscroll_window_->SetName("OverscrollOverlay"); |
945 | 945 |
946 overscroll_change_brightness_ = overscroll_delegate->has_screenshot(); | 946 overscroll_change_brightness_ = overscroll_delegate->has_screenshot(); |
947 window_->AddChild(overscroll_window_.get()); | 947 window_->AddChild(overscroll_window_.get()); |
948 | 948 |
949 gfx::Rect bounds = gfx::Rect(window_->bounds().size()); | 949 gfx::Rect bounds = gfx::Rect(window_->bounds().size()); |
950 if (ShouldNavigateForward(web_contents_->GetController(), | 950 if (ShouldNavigateForward(web_contents_->GetController(), |
951 current_overscroll_gesture_)) { | 951 current_overscroll_gesture_)) { |
952 // The overlay will be sliding in from the right edge towards the left in | 952 // The overlay will be sliding in from the right edge towards the left in |
953 // non-RTL, or sliding in from the left edge towards the right in RTL. | 953 // non-RTL, or sliding in from the left edge towards the right in RTL. |
954 // So position the overlay window accordingly. | 954 // So position the overlay window accordingly. |
955 bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0); | 955 bounds.Offset(base::i18n::IsRTL() ? -bounds.width() : bounds.width(), 0); |
956 } | 956 } |
957 | 957 |
958 if (GetWindowToAnimateForOverscroll() == overscroll_window_.get()) { | 958 if (GetWindowToAnimateForOverscroll() == overscroll_window_) { |
959 overscroll_delegate->set_show_shadow(true); | 959 overscroll_delegate->set_show_shadow(true); |
960 window_->StackChildAbove(overscroll_window_.get(), content_container_); | 960 window_->StackChildAbove(overscroll_window_.get(), content_container_); |
961 } else { | 961 } else { |
962 window_->StackChildBelow(overscroll_window_.get(), content_container_); | 962 window_->StackChildBelow(overscroll_window_.get(), content_container_); |
963 | 963 |
964 switch (current_overscroll_gesture_) { | 964 switch (current_overscroll_gesture_) { |
965 case OVERSCROLL_EAST: | 965 case OVERSCROLL_EAST: |
966 content_container_->SetShadowEdge(SHADOW_LEFT); | 966 content_container_->SetShadowEdge(SHADOW_LEFT); |
967 break; | 967 break; |
968 | 968 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1169 } | 1169 } |
1170 | 1170 |
1171 void WebContentsViewAura::SetInitialFocus() { | 1171 void WebContentsViewAura::SetInitialFocus() { |
1172 if (web_contents_->FocusLocationBarByDefault()) | 1172 if (web_contents_->FocusLocationBarByDefault()) |
1173 web_contents_->SetFocusToLocationBar(false); | 1173 web_contents_->SetFocusToLocationBar(false); |
1174 else | 1174 else |
1175 Focus(); | 1175 Focus(); |
1176 } | 1176 } |
1177 | 1177 |
1178 void WebContentsViewAura::StoreFocus() { | 1178 void WebContentsViewAura::StoreFocus() { |
1179 if (delegate_.get()) | 1179 if (delegate_) |
1180 delegate_->StoreFocus(); | 1180 delegate_->StoreFocus(); |
1181 } | 1181 } |
1182 | 1182 |
1183 void WebContentsViewAura::RestoreFocus() { | 1183 void WebContentsViewAura::RestoreFocus() { |
1184 if (delegate_.get()) | 1184 if (delegate_) |
1185 delegate_->RestoreFocus(); | 1185 delegate_->RestoreFocus(); |
1186 } | 1186 } |
1187 | 1187 |
1188 WebDropData* WebContentsViewAura::GetDropData() const { | 1188 WebDropData* WebContentsViewAura::GetDropData() const { |
1189 return current_drop_data_.get(); | 1189 return current_drop_data_.get(); |
1190 } | 1190 } |
1191 | 1191 |
1192 gfx::Rect WebContentsViewAura::GetViewBounds() const { | 1192 gfx::Rect WebContentsViewAura::GetViewBounds() const { |
1193 return window_->GetBoundsInScreen(); | 1193 return window_->GetBoundsInScreen(); |
1194 } | 1194 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 window_->SetName("WebContentsViewAura"); | 1226 window_->SetName("WebContentsViewAura"); |
1227 | 1227 |
1228 window_observer_.reset(new WindowObserver(this)); | 1228 window_observer_.reset(new WindowObserver(this)); |
1229 #if defined(OS_WIN) | 1229 #if defined(OS_WIN) |
1230 child_window_observer_.reset(new ChildWindowObserver(this)); | 1230 child_window_observer_.reset(new ChildWindowObserver(this)); |
1231 #endif | 1231 #endif |
1232 | 1232 |
1233 // delegate_->GetDragDestDelegate() creates a new delegate on every call. | 1233 // delegate_->GetDragDestDelegate() creates a new delegate on every call. |
1234 // Hence, we save a reference to it locally. Similar model is used on other | 1234 // Hence, we save a reference to it locally. Similar model is used on other |
1235 // platforms as well. | 1235 // platforms as well. |
1236 if (delegate_.get()) | 1236 if (delegate_) |
1237 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); | 1237 drag_dest_delegate_ = delegate_->GetDragDestDelegate(); |
1238 } | 1238 } |
1239 | 1239 |
1240 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( | 1240 RenderWidgetHostView* WebContentsViewAura::CreateViewForWidget( |
1241 RenderWidgetHost* render_widget_host) { | 1241 RenderWidgetHost* render_widget_host) { |
1242 if (render_widget_host->GetView()) { | 1242 if (render_widget_host->GetView()) { |
1243 // During testing, the view will already be set up in most cases to the | 1243 // During testing, the view will already be set up in most cases to the |
1244 // test view, so we don't want to clobber it with a real one. To verify that | 1244 // test view, so we don't want to clobber it with a real one. To verify that |
1245 // this actually is happening (and somebody isn't accidentally creating the | 1245 // this actually is happening (and somebody isn't accidentally creating the |
1246 // view twice), we check for the RVH Factory, which will be set when we're | 1246 // view twice), we check for the RVH Factory, which will be set when we're |
(...skipping 16 matching lines...) Expand all Loading... |
1263 view->Show(); | 1263 view->Show(); |
1264 | 1264 |
1265 // We listen to drag drop events in the newly created view's window. | 1265 // We listen to drag drop events in the newly created view's window. |
1266 aura::client::SetDragDropDelegate(view->GetNativeView(), this); | 1266 aura::client::SetDragDropDelegate(view->GetNativeView(), this); |
1267 | 1267 |
1268 RenderWidgetHostImpl* host_impl = | 1268 RenderWidgetHostImpl* host_impl = |
1269 RenderWidgetHostImpl::From(render_widget_host); | 1269 RenderWidgetHostImpl::From(render_widget_host); |
1270 if (host_impl->overscroll_controller() && web_contents_->GetDelegate() && | 1270 if (host_impl->overscroll_controller() && web_contents_->GetDelegate() && |
1271 web_contents_->GetDelegate()->CanOverscrollContent()) { | 1271 web_contents_->GetDelegate()->CanOverscrollContent()) { |
1272 host_impl->overscroll_controller()->set_delegate(this); | 1272 host_impl->overscroll_controller()->set_delegate(this); |
1273 if (!navigation_overlay_.get()) | 1273 if (!navigation_overlay_) |
1274 navigation_overlay_.reset(new OverscrollNavigationOverlay()); | 1274 navigation_overlay_.reset(new OverscrollNavigationOverlay()); |
1275 } | 1275 } |
1276 | 1276 |
1277 return view; | 1277 return view; |
1278 } | 1278 } |
1279 | 1279 |
1280 RenderWidgetHostView* WebContentsViewAura::CreateViewForPopupWidget( | 1280 RenderWidgetHostView* WebContentsViewAura::CreateViewForPopupWidget( |
1281 RenderWidgetHost* render_widget_host) { | 1281 RenderWidgetHost* render_widget_host) { |
1282 return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host); | 1282 return RenderWidgetHostViewPort::CreateViewForWidget(render_widget_host); |
1283 } | 1283 } |
(...skipping 21 matching lines...) Expand all Loading... |
1305 host->overscroll_controller()->set_delegate(this); | 1305 host->overscroll_controller()->set_delegate(this); |
1306 } | 1306 } |
1307 } | 1307 } |
1308 | 1308 |
1309 //////////////////////////////////////////////////////////////////////////////// | 1309 //////////////////////////////////////////////////////////////////////////////// |
1310 // WebContentsViewAura, RenderViewHostDelegateView implementation: | 1310 // WebContentsViewAura, RenderViewHostDelegateView implementation: |
1311 | 1311 |
1312 void WebContentsViewAura::ShowContextMenu( | 1312 void WebContentsViewAura::ShowContextMenu( |
1313 const ContextMenuParams& params, | 1313 const ContextMenuParams& params, |
1314 ContextMenuSourceType type) { | 1314 ContextMenuSourceType type) { |
1315 if (delegate_.get()) | 1315 if (delegate_) |
1316 delegate_->ShowContextMenu(params, type); | 1316 delegate_->ShowContextMenu(params, type); |
1317 } | 1317 } |
1318 | 1318 |
1319 void WebContentsViewAura::ShowPopupMenu(const gfx::Rect& bounds, | 1319 void WebContentsViewAura::ShowPopupMenu(const gfx::Rect& bounds, |
1320 int item_height, | 1320 int item_height, |
1321 double item_font_size, | 1321 double item_font_size, |
1322 int selected_item, | 1322 int selected_item, |
1323 const std::vector<WebMenuItem>& items, | 1323 const std::vector<WebMenuItem>& items, |
1324 bool right_aligned, | 1324 bool right_aligned, |
1325 bool allow_multiple_selection) { | 1325 bool allow_multiple_selection) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 return gfx::Size(); | 1486 return gfx::Size(); |
1487 } | 1487 } |
1488 | 1488 |
1489 gfx::Size WebContentsViewAura::GetMaximumSize() const { | 1489 gfx::Size WebContentsViewAura::GetMaximumSize() const { |
1490 return gfx::Size(); | 1490 return gfx::Size(); |
1491 } | 1491 } |
1492 | 1492 |
1493 void WebContentsViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, | 1493 void WebContentsViewAura::OnBoundsChanged(const gfx::Rect& old_bounds, |
1494 const gfx::Rect& new_bounds) { | 1494 const gfx::Rect& new_bounds) { |
1495 SizeChangedCommon(new_bounds.size()); | 1495 SizeChangedCommon(new_bounds.size()); |
1496 if (delegate_.get()) | 1496 if (delegate_) |
1497 delegate_->SizeChanged(new_bounds.size()); | 1497 delegate_->SizeChanged(new_bounds.size()); |
1498 | 1498 |
1499 // Constrained web dialogs, need to be kept centered over our content area. | 1499 // Constrained web dialogs, need to be kept centered over our content area. |
1500 for (size_t i = 0; i < window_->children().size(); i++) { | 1500 for (size_t i = 0; i < window_->children().size(); i++) { |
1501 if (window_->children()[i]->GetProperty( | 1501 if (window_->children()[i]->GetProperty( |
1502 aura::client::kConstrainedWindowKey)) { | 1502 aura::client::kConstrainedWindowKey)) { |
1503 gfx::Rect bounds = window_->children()[i]->bounds(); | 1503 gfx::Rect bounds = window_->children()[i]->bounds(); |
1504 bounds.set_origin( | 1504 bounds.set_origin( |
1505 gfx::Point((new_bounds.width() - bounds.width()) / 2, | 1505 gfx::Point((new_bounds.width() - bounds.width()) / 2, |
1506 (new_bounds.height() - bounds.height()) / 2)); | 1506 (new_bounds.height() - bounds.height()) / 2)); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 event.location(), | 1662 event.location(), |
1663 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1663 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1664 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1664 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1665 if (drag_dest_delegate_) | 1665 if (drag_dest_delegate_) |
1666 drag_dest_delegate_->OnDrop(); | 1666 drag_dest_delegate_->OnDrop(); |
1667 current_drop_data_.reset(); | 1667 current_drop_data_.reset(); |
1668 return current_drag_op_; | 1668 return current_drag_op_; |
1669 } | 1669 } |
1670 | 1670 |
1671 } // namespace content | 1671 } // namespace content |
OLD | NEW |