Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: ui/views/widget/native_widget_aura.cc

Issue 11421006: Desktop aura: Break aura::Window::SetParent in two. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ash_unittests Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/corewm/shadow_controller_unittest.cc ('k') | ui/views/widget/widget.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 (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 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 Widget::Widgets widgets; 1023 Widget::Widgets widgets;
1021 GetAllChildWidgets(native_view, &widgets); 1024 GetAllChildWidgets(native_view, &widgets);
1022 1025
1023 // First notify all the widgets that they are being disassociated 1026 // First notify all the widgets that they are being disassociated
1024 // from their previous parent. 1027 // from their previous parent.
1025 for (Widget::Widgets::iterator it = widgets.begin(); 1028 for (Widget::Widgets::iterator it = widgets.begin();
1026 it != widgets.end(); ++it) { 1029 it != widgets.end(); ++it) {
1027 (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent); 1030 (*it)->NotifyNativeViewHierarchyChanged(false, previous_parent);
1028 } 1031 }
1029 1032
1030 native_view->SetParent(new_parent); 1033 if (new_parent) {
1034 new_parent->AddChild(native_view);
1035 } else {
1036 // The following looks weird, but it's the equivalent of what aura has
1037 // always done. (The previous behaviour of aura::Window::SetParent() used
1038 // NULL as a special value that meant ask the StackingClient where things
1039 // should go.)
1040 //
1041 // This probably isn't strictly correct, but its an invariant that a Window
1042 // in use will be attached to a RootWindow, so we can't just call
1043 // RemoveChild here. The only possible thing that could assign a RootWindow
1044 // in this case is the stacking client of the current RootWindow. This
1045 // matches our previous behaviour; the global stacking client would almost
1046 // always reattach the window to the same RootWindow.
1047 native_view->SetDefaultParentByRootWindow(native_view->GetRootWindow(),
1048 gfx::Rect());
1049 }
1031 1050
1032 // And now, notify them that they have a brand new parent. 1051 // And now, notify them that they have a brand new parent.
1033 for (Widget::Widgets::iterator it = widgets.begin(); 1052 for (Widget::Widgets::iterator it = widgets.begin();
1034 it != widgets.end(); ++it) { 1053 it != widgets.end(); ++it) {
1035 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); 1054 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent);
1036 } 1055 }
1037 } 1056 }
1038 1057
1039 // static 1058 // static
1040 bool NativeWidgetPrivate::IsMouseButtonDown() { 1059 bool NativeWidgetPrivate::IsMouseButtonDown() {
1041 return aura::Env::GetInstance()->is_mouse_button_down(); 1060 return aura::Env::GetInstance()->is_mouse_button_down();
1042 } 1061 }
1043 1062
1044 // static 1063 // static
1045 bool NativeWidgetPrivate::IsTouchDown() { 1064 bool NativeWidgetPrivate::IsTouchDown() {
1046 return aura::Env::GetInstance()->is_touch_down(); 1065 return aura::Env::GetInstance()->is_touch_down();
1047 } 1066 }
1048 1067
1049 } // namespace internal 1068 } // namespace internal
1050 } // namespace views 1069 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/shadow_controller_unittest.cc ('k') | ui/views/widget/widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698