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 // If the parent is not specified, find the default parent for |
124 // the |window_| using the desired |window_bounds|. | 122 // the |window_| using the desired |window_bounds|. |
125 if (!parent) { | 123 if (!parent) { |
126 parent = aura::client::GetStackingClient(params.GetParent())-> | 124 parent = aura::client::GetStackingClient(params.GetParent())-> |
127 GetDefaultParent(params.context, window_, window_bounds); | 125 GetDefaultParent(params.context, window_, window_bounds); |
128 } else if (window_bounds == gfx::Rect()) { | 126 } else if (window_bounds == gfx::Rect()) { |
129 // If a parent is specified but no bounds are given, | 127 // If a parent is specified but no bounds are given, |
130 // use the origin of the parent's display so that the widget | 128 // use the origin of the parent's display so that the widget |
131 // will be added to the same display as the parent. | 129 // will be added to the same display as the parent. |
132 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> | 130 gfx::Rect bounds = gfx::Screen::GetScreenFor(parent)-> |
133 GetDisplayNearestWindow(parent).bounds(); | 131 GetDisplayNearestWindow(parent).bounds(); |
134 window_bounds.set_origin(bounds.origin()); | 132 window_bounds.set_origin(bounds.origin()); |
135 } | 133 } |
136 window_->SetParent(parent); | 134 } else if (!parent) { |
135 parent = aura::client::GetStackingClient(params.context)-> | |
Ben Goodger (Google)
2012/11/20 23:46:38
is there a reason we can't just follow the pattern
| |
136 GetDefaultParent(params.context, window_, window_bounds); | |
137 } | 137 } |
138 window_->SetParentTo(parent); | |
138 | 139 |
139 // Wait to set the bounds until we have a parent. That way we can know our | 140 // 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 | 141 // true state/bounds (the LayoutManager may enforce a particular |
141 // state/bounds). | 142 // state/bounds). |
142 if (IsMaximized()) | 143 if (IsMaximized()) |
143 SetRestoreBounds(window_, window_bounds); | 144 SetRestoreBounds(window_, window_bounds); |
144 else | 145 else |
145 SetBounds(window_bounds); | 146 SetBounds(window_bounds); |
146 window_->set_ignore_events(!params.accept_events); | 147 window_->set_ignore_events(!params.accept_events); |
147 can_activate_ = | 148 can_activate_ = |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1015 Widget::Widgets widgets; | 1016 Widget::Widgets widgets; |
1016 GetAllChildWidgets(native_view, &widgets); | 1017 GetAllChildWidgets(native_view, &widgets); |
1017 | 1018 |
1018 // First notify all the widgets that they are being disassociated | 1019 // First notify all the widgets that they are being disassociated |
1019 // from their previous parent. | 1020 // from their previous parent. |
1020 for (Widget::Widgets::iterator it = widgets.begin(); | 1021 for (Widget::Widgets::iterator it = widgets.begin(); |
1021 it != widgets.end(); ++it) { | 1022 it != widgets.end(); ++it) { |
1022 (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); | 1023 (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); |
1023 } | 1024 } |
1024 | 1025 |
1025 native_view->SetParent(new_parent); | 1026 if (new_parent) { |
1027 native_view->SetParentTo(new_parent); | |
1028 } else { | |
1029 // I am unsure what we should really be doing here. The following looks | |
1030 // weird, but it's the equivalent of what aura has always done. (The | |
1031 // previous behaviour of aura::Window::SetParent() used NULL as a special | |
1032 // value that meant ask the StackingClient where things should go.) jam@ | |
1033 // reasonably thought that was stupid and replaced it with a RemoveChild | |
1034 // call, which broke things hard. | |
1035 native_view->SetDefaultParentByTargetRoot(native_view->GetRootWindow()); | |
1036 } | |
1026 | 1037 |
1027 // And now, notify them that they have a brand new parent. | 1038 // And now, notify them that they have a brand new parent. |
1028 for (Widget::Widgets::iterator it = widgets.begin(); | 1039 for (Widget::Widgets::iterator it = widgets.begin(); |
1029 it != widgets.end(); ++it) { | 1040 it != widgets.end(); ++it) { |
1030 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); | 1041 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); |
1031 } | 1042 } |
1032 } | 1043 } |
1033 | 1044 |
1034 // static | 1045 // static |
1035 bool NativeWidgetPrivate::IsMouseButtonDown() { | 1046 bool NativeWidgetPrivate::IsMouseButtonDown() { |
1036 return aura::Env::GetInstance()->is_mouse_button_down(); | 1047 return aura::Env::GetInstance()->is_mouse_button_down(); |
1037 } | 1048 } |
1038 | 1049 |
1039 // static | 1050 // static |
1040 bool NativeWidgetPrivate::IsTouchDown() { | 1051 bool NativeWidgetPrivate::IsTouchDown() { |
1041 return aura::Env::GetInstance()->is_touch_down(); | 1052 return aura::Env::GetInstance()->is_touch_down(); |
1042 } | 1053 } |
1043 | 1054 |
1044 } // namespace internal | 1055 } // namespace internal |
1045 } // namespace views | 1056 } // namespace views |
OLD | NEW |