Chromium Code Reviews| 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 // Check if a given |child_window| is below a given |window| in the hierarchy. | |
| 102 bool IsInHierarchyBelow(aura::Window* child_window, aura::Window* window) { | |
| 103 aura::Window* childs_parent = child_window->parent(); | |
| 104 if (!childs_parent) | |
| 105 return false; | |
| 106 if (childs_parent == window) | |
| 107 return true; | |
| 108 return IsInHierarchyBelow(childs_parent, window); | |
| 109 } | |
| 110 | |
| 111 // Update the |visibility| of the |web contents|. | |
| 112 void UpdateWebContentsVisibility(WebContentsImpl* web_contents, | |
| 113 bool visibility) { | |
| 114 if (visibility) { | |
| 115 if (!web_contents->should_normally_be_visible()) | |
| 116 web_contents->WasShown(); | |
| 117 } else { | |
| 118 if (web_contents->should_normally_be_visible()) | |
| 119 web_contents->WasHidden(); | |
| 120 } | |
| 121 } | |
| 122 | |
| 101 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( | 123 RenderWidgetHostViewAura* ToRenderWidgetHostViewAura( |
| 102 RenderWidgetHostView* view) { | 124 RenderWidgetHostView* view) { |
| 103 if (!view || RenderViewHostFactory::has_factory()) | 125 if (!view || RenderViewHostFactory::has_factory()) |
| 104 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. | 126 return NULL; // Can't cast to RenderWidgetHostViewAura in unit tests. |
| 105 RenderProcessHostImpl* process = static_cast<RenderProcessHostImpl*>( | 127 RenderProcessHostImpl* process = static_cast<RenderProcessHostImpl*>( |
| 106 view->GetRenderWidgetHost()->GetProcess()); | 128 view->GetRenderWidgetHost()->GetProcess()); |
| 107 if (process->IsGuest()) | 129 if (process->IsGuest()) |
| 108 return NULL; | 130 return NULL; |
| 109 return static_cast<RenderWidgetHostViewAura*>(view); | 131 return static_cast<RenderWidgetHostViewAura*>(view); |
| 110 } | 132 } |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 // WebContentsViewAura, private: | 736 // WebContentsViewAura, private: |
| 715 | 737 |
| 716 WebContentsViewAura::~WebContentsViewAura() { | 738 WebContentsViewAura::~WebContentsViewAura() { |
| 717 if (!window_) | 739 if (!window_) |
| 718 return; | 740 return; |
| 719 | 741 |
| 720 window_observer_.reset(); | 742 window_observer_.reset(); |
| 721 | 743 |
| 722 // Window needs a valid delegate during its destructor, so we explicitly | 744 // Window needs a valid delegate during its destructor, so we explicitly |
| 723 // delete it here. | 745 // delete it here. |
| 746 window_->RemoveObserver(this); | |
| 724 window_.reset(); | 747 window_.reset(); |
| 725 } | 748 } |
| 726 | 749 |
| 727 void WebContentsViewAura::SetupOverlayWindowForTesting() { | 750 void WebContentsViewAura::SetupOverlayWindowForTesting() { |
| 728 if (navigation_overlay_) | 751 if (navigation_overlay_) |
| 729 navigation_overlay_->SetupForTesting(); | 752 navigation_overlay_->SetupForTesting(); |
| 730 } | 753 } |
| 731 | 754 |
| 732 void WebContentsViewAura::SetTouchEditableForTest( | 755 void WebContentsViewAura::SetTouchEditableForTest( |
| 733 TouchEditableImplAura* touch_editable) { | 756 TouchEditableImplAura* touch_editable) { |
| (...skipping 304 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 | 1061 // 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 | 1062 // 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. | 1063 // value is set shortly after this, so its safe to ignore. |
| 1041 | 1064 |
| 1042 aura::Env::CreateInstance(true); | 1065 aura::Env::CreateInstance(true); |
| 1043 window_.reset(new aura::Window(this)); | 1066 window_.reset(new aura::Window(this)); |
| 1044 window_->set_owned_by_parent(false); | 1067 window_->set_owned_by_parent(false); |
| 1045 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); | 1068 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); |
| 1046 window_->SetTransparent(false); | 1069 window_->SetTransparent(false); |
| 1047 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 1070 window_->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 1071 window_->AddObserver(this); | |
| 1048 aura::Window* root_window = context ? context->GetRootWindow() : NULL; | 1072 aura::Window* root_window = context ? context->GetRootWindow() : NULL; |
| 1049 if (root_window) { | 1073 if (root_window) { |
| 1050 // There are places where there is no context currently because object | 1074 // There are places where there is no context currently because object |
| 1051 // hierarchies are built before they're attached to a Widget. (See | 1075 // hierarchies are built before they're attached to a Widget. (See |
| 1052 // views::WebView as an example; GetWidget() returns NULL at the point | 1076 // views::WebView as an example; GetWidget() returns NULL at the point |
| 1053 // where we are created.) | 1077 // where we are created.) |
| 1054 // | 1078 // |
| 1055 // It should be OK to not set a default parent since such users will | 1079 // 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 | 1080 // explicitly add this WebContentsViewAura to their tree after they create |
| 1057 // us. | 1081 // us. |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1422 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So | 1446 // virtual functions to be called (e.g. OnImplicitAnimationsCompleted()). So |
| 1423 // destroy the overscroll window here. | 1447 // destroy the overscroll window here. |
| 1424 navigation_overlay_.reset(); | 1448 navigation_overlay_.reset(); |
| 1425 overscroll_window_.reset(); | 1449 overscroll_window_.reset(); |
| 1426 } | 1450 } |
| 1427 | 1451 |
| 1428 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { | 1452 void WebContentsViewAura::OnWindowDestroyed(aura::Window* window) { |
| 1429 } | 1453 } |
| 1430 | 1454 |
| 1431 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { | 1455 void WebContentsViewAura::OnWindowTargetVisibilityChanged(bool visible) { |
| 1432 if (visible) | |
| 1433 web_contents_->WasShown(); | |
| 1434 else | |
| 1435 web_contents_->WasHidden(); | |
| 1436 } | 1456 } |
| 1437 | 1457 |
| 1438 bool WebContentsViewAura::HasHitTestMask() const { | 1458 bool WebContentsViewAura::HasHitTestMask() const { |
| 1439 return false; | 1459 return false; |
| 1440 } | 1460 } |
| 1441 | 1461 |
| 1442 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const { | 1462 void WebContentsViewAura::GetHitTestMask(gfx::Path* mask) const { |
| 1443 } | 1463 } |
| 1444 | 1464 |
| 1445 //////////////////////////////////////////////////////////////////////////////// | 1465 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1548 web_contents_->GetRenderViewHost()->DragTargetDrop( | 1568 web_contents_->GetRenderViewHost()->DragTargetDrop( |
| 1549 event.location(), | 1569 event.location(), |
| 1550 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), | 1570 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), |
| 1551 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); | 1571 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); |
| 1552 if (drag_dest_delegate_) | 1572 if (drag_dest_delegate_) |
| 1553 drag_dest_delegate_->OnDrop(); | 1573 drag_dest_delegate_->OnDrop(); |
| 1554 current_drop_data_.reset(); | 1574 current_drop_data_.reset(); |
| 1555 return ConvertFromWeb(current_drag_op_); | 1575 return ConvertFromWeb(current_drag_op_); |
| 1556 } | 1576 } |
| 1557 | 1577 |
| 1578 void WebContentsViewAura::OnWindowParentChanged(aura::Window* window, | |
| 1579 aura::Window* parent) { | |
| 1580 UpdateWebContentsVisibility(web_contents_, !parent || parent->IsVisible()); | |
| 1581 } | |
| 1582 | |
| 1583 void WebContentsViewAura::OnWindowVisibilityChanged(aura::Window* window, | |
| 1584 bool visible) { | |
| 1585 // Ignore any visibility changes in the hierarchy below. | |
| 1586 if (IsInHierarchyBelow(window, window_.get())) | |
|
sky
2014/05/20 19:46:27
Isn't this the same as window_->Contains(window) &
Mr4D (OOO till 08-26)
2014/05/20 21:26:56
Done.
| |
| 1587 return; | |
| 1588 | |
| 1589 UpdateWebContentsVisibility(web_contents_, visible); | |
| 1590 } | |
| 1591 | |
| 1558 } // namespace content | 1592 } // namespace content |
| OLD | NEW |