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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && | 91 return mode == (base::i18n::IsRTL() ? OVERSCROLL_EAST : OVERSCROLL_WEST) && |
92 controller.CanGoForward(); | 92 controller.CanGoForward(); |
93 } | 93 } |
94 | 94 |
95 bool ShouldNavigateBack(const NavigationController& controller, | 95 bool ShouldNavigateBack(const NavigationController& controller, |
96 OverscrollMode mode) { | 96 OverscrollMode mode) { |
97 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && | 97 return mode == (base::i18n::IsRTL() ? OVERSCROLL_WEST : OVERSCROLL_EAST) && |
98 controller.CanGoBack(); | 98 controller.CanGoBack(); |
99 } | 99 } |
100 | 100 |
| 101 // Update the |web contents| to be |visible|. |
| 102 void UpdateWebContentsVisibility(WebContentsImpl* web_contents, bool visible) { |
| 103 if (visible) { |
| 104 if (!web_contents->should_normally_be_visible()) |
| 105 web_contents->WasShown(); |
| 106 } else { |
| 107 if (web_contents->should_normally_be_visible()) |
| 108 web_contents->WasHidden(); |
| 109 } |
| 110 } |
| 111 |
101 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( | 112 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( |
102 RenderWidgetHostView* view) { | 113 RenderWidgetHostView* view) { |
103 if (!view || RenderViewHostFactory::has_factory()) | 114 if (!view || RenderViewHostFactory::has_factory()) |
104 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. | 115 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. |
105 RenderProcessHostImpl* process = static_cast<RenderProcessHostImpl*>( | 116 RenderProcessHostImpl* process = static_cast<RenderProcessHostImpl*>( |
106 view->GetRenderWidgetHost()->GetProcess()); | 117 view->GetRenderWidgetHost()->GetProcess()); |
107 if (process->IsGuest()) | 118 if (process->IsGuest()) |
108 return NULL; | 119 return NULL; |
109 return static_cast<RenderWidgetHostViewAura*>(view); | 120 return static_cast<RenderWidgetHostViewAura*>(view); |
110 } | 121 } |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 } | 722 } |
712 | 723 |
713 //////////////////////////////////////////////////////////////////////////////// | 724 //////////////////////////////////////////////////////////////////////////////// |
714 // WebContentsViewAura, private: | 725 // WebContentsViewAura, private: |
715 | 726 |
716 WebContentsViewAura::~WebContentsViewAura() { | 727 WebContentsViewAura::~WebContentsViewAura() { |
717 if (!window_) | 728 if (!window_) |
718 return; | 729 return; |
719 | 730 |
720 window_observer_.reset(); | 731 window_observer_.reset(); |
| 732 window_->RemoveObserver(this); |
721 | 733 |
722 // Window needs a valid delegate during its destructor, so we explicitly | 734 // Window needs a valid delegate during its destructor, so we explicitly |
723 // delete it here. | 735 // delete it here. |
724 window_.reset(); | 736 window_.reset(); |
725 } | 737 } |
726 | 738 |
727 void WebContentsViewAura::SetupOverlayWindowForTesting() { | 739 void WebContentsViewAura::SetupOverlayWindowForTesting() { |
728 if (navigation_overlay_) | 740 if (navigation_overlay_) |
729 navigation_overlay_->SetupForTesting(); | 741 navigation_overlay_->SetupForTesting(); |
730 } | 742 } |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 // NOTE: we ignore |initial_size| since in some cases it's wrong (such as | 1050 // NOTE: we ignore |initial_size| since in some cases it's wrong (such as |
1039 // if the bookmark bar is not shown and you create a new tab). The right | 1051 // if the bookmark bar is not shown and you create a new tab). The right |
1040 // value is set shortly after this, so its safe to ignore. | 1052 // value is set shortly after this, so its safe to ignore. |
1041 | 1053 |
1042 aura::Env::CreateInstance(true); | 1054 aura::Env::CreateInstance(true); |
1043 window_.reset(new aura::Window(this)); | 1055 window_.reset(new aura::Window(this)); |
1044 window_->set_owned_by_parent(false); | 1056 window_->set_owned_by_parent(false); |
1045 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 1057 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
1046 window_->SetTransparent(false); | 1058 window_->SetTransparent(false); |
1047 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 1059 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 1060 window_->AddObserver(this); |
1048 aura::Window* root_window = context ? context->GetRootWindow() : NULL; | 1061 aura::Window* root_window = context ? context->GetRootWindow() : NULL; |
1049 if (root_window) { | 1062 if (root_window) { |
1050 // There are places where there is no context currently because object | 1063 // There are places where there is no context currently because object |
1051 // hierarchies are built before they're attached to a Widget. (See | 1064 // hierarchies are built before they're attached to a Widget. (See |
1052 // views::WebView as an example; GetWidget() returns NULL at the point | 1065 // views::WebView as an example; GetWidget() returns NULL at the point |
1053 // where we are created.) | 1066 // where we are created.) |
1054 // | 1067 // |
1055 // It should be OK to not set a default parent since such users will | 1068 // It should be OK to not set a default parent since such users will |
1056 // explicitly add this WebContentsViewAura to their tree after they create | 1069 // explicitly add this WebContentsViewAura to their tree after they create |
1057 // us. | 1070 // us. |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So | 1433 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So |
1421 // destroy the overscroll window here. | 1434 // destroy the overscroll window here. |
1422 navigation_overlay_.reset(); | 1435 navigation_overlay_.reset(); |
1423 overscroll_window_.reset(); | 1436 overscroll_window_.reset(); |
1424 } | 1437 } |
1425 | 1438 |
1426 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { | 1439 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { |
1427 } | 1440 } |
1428 | 1441 |
1429 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { | 1442 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { |
1430 if (visible) | |
1431 web_contents_->WasShown(); | |
1432 else | |
1433 web_contents_->WasHidden(); | |
1434 } | 1443 } |
1435 | 1444 |
1436 bool WebContentsViewAura::HasHitTestMask() const { | 1445 bool WebContentsViewAura::HasHitTestMask() const { |
1437 return false; | 1446 return false; |
1438 } | 1447 } |
1439 | 1448 |
1440 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const { | 1449 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const { |
1441 } | 1450 } |
1442 | 1451 |
1443 //////////////////////////////////////////////////////////////////////////////// | 1452 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1546 web_contents_->GetRenderViewHost()->DragTargetDrop( | 1555 web_contents_->GetRenderViewHost()->DragTargetDrop( |
1547 event.location(), | 1556 event.location(), |
1548 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1557 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
1549 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1558 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
1550 if (drag_dest_delegate_) | 1559 if (drag_dest_delegate_) |
1551 drag_dest_delegate_->OnDrop(); | 1560 drag_dest_delegate_->OnDrop(); |
1552 current_drop_data_.reset(); | 1561 current_drop_data_.reset(); |
1553 return ConvertFromWeb(current_drag_op_); | 1562 return ConvertFromWeb(current_drag_op_); |
1554 } | 1563 } |
1555 | 1564 |
| 1565 void WebContentsViewAura::OnWindowParentChanged(aura::Window* window, |
| 1566 aura::Window* parent) { |
| 1567 // On Windows we will get called with a parent of NULL as part of the shut |
| 1568 // down process. As such we do only change the visibility when a parent gets |
| 1569 // set. |
| 1570 if (parent) |
| 1571 UpdateWebContentsVisibility(web_contents_, window->IsVisible()); |
| 1572 } |
| 1573 |
| 1574 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, |
| 1575 bool visible) { |
| 1576 // Ignore any visibility changes in the hierarchy below. |
| 1577 if (window != window_.get() && window_->Contains(window)) |
| 1578 return; |
| 1579 |
| 1580 UpdateWebContentsVisibility(web_contents_, visible); |
| 1581 } |
| 1582 |
1556 } // namespace content | 1583 } // namespace content |
OLD | NEW |