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 "ui/views/widget/native_widget_aura.h" | 5 #include "ui/views/widget/native_widget_aura.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "third_party/skia/include/core/SkRegion.h" | 9 #include "third_party/skia/include/core/SkRegion.h" |
10 #include "ui/aura/client/activation_change_observer.h" | 10 #include "ui/aura/client/activation_change_observer.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 if (params.type == Widget::InitParams::TYPE_BUBBLE) | 101 if (params.type == Widget::InitParams::TYPE_BUBBLE) |
102 aura::client::SetHideOnDeactivate(window_, true); | 102 aura::client::SetHideOnDeactivate(window_, true); |
103 window_->SetTransparent(params.transparent); | 103 window_->SetTransparent(params.transparent); |
104 window_->Init(params.layer_type); | 104 window_->Init(params.layer_type); |
105 if (params.type == Widget::InitParams::TYPE_CONTROL) | 105 if (params.type == Widget::InitParams::TYPE_CONTROL) |
106 window_->Show(); | 106 window_->Show(); |
107 | 107 |
108 delegate_->OnNativeWidgetCreated(); | 108 delegate_->OnNativeWidgetCreated(); |
109 | 109 |
110 gfx::Rect window_bounds = params.bounds; | 110 gfx::Rect window_bounds = params.bounds; |
111 if (params.child) { | 111 gfx::NativeView parent = params.GetParent(); |
112 window_->SetParent(params.GetParent()); | 112 if (!params.child) { |
113 } else { | |
114 // Set up the transient child before the window is added. This way the | 113 // Set up the transient child before the window is added. This way the |
115 // LayoutManager knows the window has a transient parent. | 114 // LayoutManager knows the window has a transient parent. |
116 gfx::NativeView parent = params.GetParent(); | |
117 if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { | 115 if (parent && parent->type() != aura::client::WINDOW_TYPE_UNKNOWN) { |
118 parent->AddTransientChild(window_); | 116 parent->AddTransientChild(window_); |
119 parent = NULL; | 117 parent = NULL; |
120 } | 118 } |
121 // SetAlwaysOnTop before SetParent so that always-on-top container is used. | 119 // SetAlwaysOnTop before SetParent so that always-on-top container is used. |
122 SetAlwaysOnTop(params.keep_on_top); | 120 SetAlwaysOnTop(params.keep_on_top); |
123 // If the parent is not specified, find the default parent for | 121 // Make sure we have a real |window_bounds|. |
124 // the |window_| using the desired |window_bounds|. | 122 if (window_bounds == gfx::Rect()) { |
oshima
2012/11/27 00:14:30
parent && window_bounds == gfx::Rect()
| |
125 if (!parent) { | |
126 parent = aura::client::GetStackingClient(params.GetParent())-> | |
127 GetDefaultParent(params.context, window_, window_bounds); | |
128 } else if (window_bounds == gfx::Rect()) { | |
129 // If a parent is specified but no bounds are given, | 123 // If a parent is specified but no bounds are given, |
130 // use the origin of the parent's display so that the widget | 124 // use the origin of the parent's display so that the widget |
131 // will be added to the same display as the parent. | 125 // will be added to the same display as the parent. |
132 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> | 126 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> |
133 GetDisplayNearestWindow(parent).bounds(); | 127 GetDisplayNearestWindow(parent).bounds(); |
134 window_bounds.set_origin(bounds.origin()); | 128 window_bounds.set_origin(bounds.origin()); |
135 } | 129 } |
136 window_->SetParent(parent); | 130 } |
131 | |
132 if (parent) { | |
133 parent->AddChild(window_); | |
134 } else { | |
135 // TODO(erg): Remove this NULL check once we've made everything in views | |
136 // actually pass us a context. | |
137 aura::RootWindow* root_window = | |
138 params.context ? params.context->GetRootWindow() : NULL; | |
139 window_->SetDefaultParentByRootWindow(root_window, window_bounds); | |
137 } | 140 } |
138 | 141 |
139 // Wait to set the bounds until we have a parent. That way we can know our | 142 // Wait to set the bounds until we have a parent. That way we can know our |
140 // true state/bounds (the LayoutManager may enforce a particular | 143 // true state/bounds (the LayoutManager may enforce a particular |
141 // state/bounds). | 144 // state/bounds). |
142 if (IsMaximized()) | 145 if (IsMaximized()) |
143 SetRestoreBounds(window_, window_bounds); | 146 SetRestoreBounds(window_, window_bounds); |
144 else | 147 else |
145 SetBounds(window_bounds); | 148 SetBounds(window_bounds); |
146 window_->set_ignore_events(!params.accept_events); | 149 window_->set_ignore_events(!params.accept_events); |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1019 Widget::Widgets widgets; | 1022 Widget::Widgets widgets; |
1020 GetAllChildWidgets(native_view, &widgets); | 1023 GetAllChildWidgets(native_view, &widgets); |
1021 | 1024 |
1022 // First notify all the widgets that they are being disassociated | 1025 // First notify all the widgets that they are being disassociated |
1023 // from their previous parent. | 1026 // from their previous parent. |
1024 for (Widget::Widgets::iterator it = widgets.begin(); | 1027 for (Widget::Widgets::iterator it = widgets.begin(); |
1025 it != widgets.end(); ++it) { | 1028 it != widgets.end(); ++it) { |
1026 (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); | 1029 (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); |
1027 } | 1030 } |
1028 | 1031 |
1029 native_view->SetParent(new_parent); | 1032 if (new_parent) { |
1033 new_parent->AddChild(native_view); | |
1034 } else { | |
1035 // The following looks weird, but it's the equivalent of what aura has | |
1036 // always done. (The previous behaviour of aura::Window::SetParent() used | |
1037 // NULL as a special value that meant ask the StackingClient where things | |
1038 // should go.) | |
1039 // | |
1040 // This probably isn't strictly correct, but its an invariant that a Window | |
1041 // in use will be attached to a RootWindow, so we can't just call | |
1042 // RemoveChild here. The only possible thing that could assign a RootWindow | |
1043 // in this case is the stacking client of the current RootWindow. This | |
1044 // matches our previous behaviour; the global stacking client would almost | |
1045 // always reattach the window to the same RootWindow. | |
1046 native_view->SetDefaultParentByRootWindow(native_view->GetRootWindow(), | |
1047 gfx::Rect()); | |
1048 } | |
1030 | 1049 |
1031 // And now, notify them that they have a brand new parent. | 1050 // And now, notify them that they have a brand new parent. |
1032 for (Widget::Widgets::iterator it = widgets.begin(); | 1051 for (Widget::Widgets::iterator it = widgets.begin(); |
1033 it != widgets.end(); ++it) { | 1052 it != widgets.end(); ++it) { |
1034 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); | 1053 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); |
1035 } | 1054 } |
1036 } | 1055 } |
1037 | 1056 |
1038 // static | 1057 // static |
1039 bool NativeWidgetPrivate::IsMouseButtonDown() { | 1058 bool NativeWidgetPrivate::IsMouseButtonDown() { |
1040 return aura::Env::GetInstance()->is_mouse_button_down(); | 1059 return aura::Env::GetInstance()->is_mouse_button_down(); |
1041 } | 1060 } |
1042 | 1061 |
1043 // static | 1062 // static |
1044 bool NativeWidgetPrivate::IsTouchDown() { | 1063 bool NativeWidgetPrivate::IsTouchDown() { |
1045 return aura::Env::GetInstance()->is_touch_down(); | 1064 return aura::Env::GetInstance()->is_touch_down(); |
1046 } | 1065 } |
1047 | 1066 |
1048 } // namespace internal | 1067 } // namespace internal |
1049 } // namespace views | 1068 } // namespace views |
OLD | NEW |