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

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: I think the content_unittests timeout on linux_aura is flake, but try to fix it anyway. Created 8 years, 1 month 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
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 (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_->SetDefaultParentByTargetRoot(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
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->SetDefaultParentByTargetRoot(native_view->GetRootWindow(),
sky 2012/11/21 23:35:59 I think this is wrong. In particular this means pa
Elliot Glaysher 2012/11/22 00:26:56 So currently this works because the StackingClient
sky 2012/11/22 00:59:50 The problem is new_parent is NULL. I'm assuming Se
Elliot Glaysher 2012/11/26 21:04:54 After talking to scottmg and jam, I'm convinced th
sky 2012/11/26 22:29:09 I agree. I think it's just your comment that needs
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698