| 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()) { |
| 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_->SetDefaultParentByRoot(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 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1015 Widget::Widgets widgets; | 1018 Widget::Widgets widgets; |
| 1016 GetAllChildWidgets(native_view, &widgets); | 1019 GetAllChildWidgets(native_view, &widgets); |
| 1017 | 1020 |
| 1018 // First notify all the widgets that they are being disassociated | 1021 // First notify all the widgets that they are being disassociated |
| 1019 // from their previous parent. | 1022 // from their previous parent. |
| 1020 for (Widget::Widgets::iterator it = widgets.begin(); | 1023 for (Widget::Widgets::iterator it = widgets.begin(); |
| 1021 it != widgets.end(); ++it) { | 1024 it != widgets.end(); ++it) { |
| 1022 (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); | 1025 (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); |
| 1023 } | 1026 } |
| 1024 | 1027 |
| 1025 native_view->SetParent(new_parent); | 1028 if (new_parent) { |
| 1029 new_parent->AddChild(native_view); |
| 1030 } else { |
| 1031 // I am unsure what we should really be doing here. The following looks |
| 1032 // weird, but it's the equivalent of what aura has always done. (The |
| 1033 // previous behaviour of aura::Window::SetParent() used NULL as a special |
| 1034 // value that meant ask the StackingClient where things should go.) jam@ |
| 1035 // reasonably thought that was stupid and replaced it with a RemoveChild |
| 1036 // call, which broke things hard. |
| 1037 native_view->SetDefaultParentByRoot(native_view->GetRootWindow(), |
| 1038 gfx::Rect()); |
| 1039 } |
| 1026 | 1040 |
| 1027 // And now, notify them that they have a brand new parent. | 1041 // And now, notify them that they have a brand new parent. |
| 1028 for (Widget::Widgets::iterator it = widgets.begin(); | 1042 for (Widget::Widgets::iterator it = widgets.begin(); |
| 1029 it != widgets.end(); ++it) { | 1043 it != widgets.end(); ++it) { |
| 1030 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); | 1044 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); |
| 1031 } | 1045 } |
| 1032 } | 1046 } |
| 1033 | 1047 |
| 1034 // static | 1048 // static |
| 1035 bool NativeWidgetPrivate::IsMouseButtonDown() { | 1049 bool NativeWidgetPrivate::IsMouseButtonDown() { |
| 1036 return aura::Env::GetInstance()->is_mouse_button_down(); | 1050 return aura::Env::GetInstance()->is_mouse_button_down(); |
| 1037 } | 1051 } |
| 1038 | 1052 |
| 1039 // static | 1053 // static |
| 1040 bool NativeWidgetPrivate::IsTouchDown() { | 1054 bool NativeWidgetPrivate::IsTouchDown() { |
| 1041 return aura::Env::GetInstance()->is_touch_down(); | 1055 return aura::Env::GetInstance()->is_touch_down(); |
| 1042 } | 1056 } |
| 1043 | 1057 |
| 1044 } // namespace internal | 1058 } // namespace internal |
| 1045 } // namespace views | 1059 } // namespace views |
| OLD | NEW |