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

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

Issue 15114002: Reorder the NativeViews attached to a view via kViewHostKey according to the position of the view (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months 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/views.gyp ('k') | ui/views/widget/native_widget_aura_unittest.cc » ('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_client.h" 10 #include "ui/aura/client/activation_client.h"
(...skipping 12 matching lines...) Expand all
23 #include "ui/base/dragdrop/os_exchange_data.h" 23 #include "ui/base/dragdrop/os_exchange_data.h"
24 #include "ui/base/events/event.h" 24 #include "ui/base/events/event.h"
25 #include "ui/base/ui_base_types.h" 25 #include "ui/base/ui_base_types.h"
26 #include "ui/compositor/layer.h" 26 #include "ui/compositor/layer.h"
27 #include "ui/gfx/canvas.h" 27 #include "ui/gfx/canvas.h"
28 #include "ui/gfx/font.h" 28 #include "ui/gfx/font.h"
29 #include "ui/gfx/screen.h" 29 #include "ui/gfx/screen.h"
30 #include "ui/native_theme/native_theme_aura.h" 30 #include "ui/native_theme/native_theme_aura.h"
31 #include "ui/views/drag_utils.h" 31 #include "ui/views/drag_utils.h"
32 #include "ui/views/ime/input_method_bridge.h" 32 #include "ui/views/ime/input_method_bridge.h"
33 #include "ui/views/view_constants_aura.h"
33 #include "ui/views/views_delegate.h" 34 #include "ui/views/views_delegate.h"
34 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 35 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
35 #include "ui/views/widget/drop_helper.h" 36 #include "ui/views/widget/drop_helper.h"
36 #include "ui/views/widget/native_widget_aura_window_observer.h" 37 #include "ui/views/widget/native_widget_aura_window_observer.h"
37 #include "ui/views/widget/native_widget_delegate.h" 38 #include "ui/views/widget/native_widget_delegate.h"
38 #include "ui/views/widget/root_view.h" 39 #include "ui/views/widget/root_view.h"
39 #include "ui/views/widget/tooltip_manager_aura.h" 40 #include "ui/views/widget/tooltip_manager_aura.h"
40 #include "ui/views/widget/widget_aura_utils.h" 41 #include "ui/views/widget/widget_aura_utils.h"
41 #include "ui/views/widget/widget_delegate.h" 42 #include "ui/views/widget/widget_delegate.h"
42 43
43 #if defined(OS_WIN) 44 #if defined(OS_WIN)
44 #include "base/win/scoped_gdi_object.h" 45 #include "base/win/scoped_gdi_object.h"
45 #include "base/win/win_util.h" 46 #include "base/win/win_util.h"
46 #include "ui/base/l10n/l10n_util_win.h" 47 #include "ui/base/l10n/l10n_util_win.h"
47 #include "ui/views/widget/desktop_aura/desktop_root_window_host_win.h" 48 #include "ui/views/widget/desktop_aura/desktop_root_window_host_win.h"
48 #endif 49 #endif
49 50
50 #if !defined(OS_CHROMEOS) 51 #if !defined(OS_CHROMEOS)
51 #include "ui/views/widget/desktop_aura/desktop_root_window_host.h" 52 #include "ui/views/widget/desktop_aura/desktop_root_window_host.h"
52 #endif 53 #endif
53 54
54 namespace views { 55 namespace views {
55 56
56 namespace { 57 namespace {
57 58
58 void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) { 59 void SetRestoreBounds(aura::Window* window, const gfx::Rect& bounds) {
59 window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds)); 60 window->SetProperty(aura::client::kRestoreBoundsKey, new gfx::Rect(bounds));
60 } 61 }
61 62
63 // Sets |order| to the list of views whose layer / attached window's layer
64 // is a child of |parent_layer|. |order| is sorted in ascending z-order of
65 // the views.
66 // |hosts| are the views with an attached window whose layer is a child of
67 // |parent_layer|. For the sake of simplificity |hosts| must all have id
68 // |host_id|.
69 void GetOrderOfViewsWithLayers(
70 views::View* current_view,
71 ui::Layer* parent_layer,
72 int host_id,
73 const std::map<views::View*, aura::Window*>& hosts,
74 std::vector<views::View*>* order) {
75 DCHECK(current_view);
76 DCHECK(parent_layer);
77 DCHECK(order);
78 if (current_view->layer() &&
79 current_view->layer()->parent() == parent_layer) {
80 order->push_back(current_view);
81 // |hosts| may contain a child of |current_view|.
82 } else if (current_view->id() == host_id &&
83 hosts.find(current_view) != hosts.end()) {
84 order->push_back(current_view);
85 return;
86 }
87
88 for (int i = 0; i < current_view->child_count(); ++i) {
89 GetOrderOfViewsWithLayers(current_view->child_at(i), parent_layer,
90 host_id, hosts, order);
91 }
92 }
93
62 } // namespace 94 } // namespace
63 95
64 //////////////////////////////////////////////////////////////////////////////// 96 ////////////////////////////////////////////////////////////////////////////////
65 // NativeWidgetAura, public: 97 // NativeWidgetAura, public:
66 98
67 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate) 99 NativeWidgetAura::NativeWidgetAura(internal::NativeWidgetDelegate* delegate)
68 : delegate_(delegate), 100 : delegate_(delegate),
69 window_(new aura::Window(this)), 101 window_(new aura::Window(this)),
70 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), 102 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET),
71 close_widget_factory_(this), 103 close_widget_factory_(this),
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 } 1056 }
1025 1057
1026 // And now, notify them that they have a brand new parent. 1058 // And now, notify them that they have a brand new parent.
1027 for (Widget::Widgets::iterator it = widgets.begin(); 1059 for (Widget::Widgets::iterator it = widgets.begin();
1028 it != widgets.end(); ++it) { 1060 it != widgets.end(); ++it) {
1029 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent); 1061 (*it)->NotifyNativeViewHierarchyChanged(true, new_parent);
1030 } 1062 }
1031 } 1063 }
1032 1064
1033 // static 1065 // static
1066 // TODO(pkotwicz): The implementation of the NativeWidgetPrivate statics is the
1067 // same for NativeWidgetAura and DesktopNativeWidgetAura. Move the
1068 // implementation of the static functions to a different file.
1069 void NativeWidgetPrivate::ReorderLayers(gfx::NativeView parent,
sky 2013/05/21 23:43:55 I think all this code should be moved into a stand
1070 View* root_view) {
1071 // Reorder the layers according to the positions of the views with layers and
1072 // views with attached windows in the view tree. The reordered layers are
1073 // positioned above layers for windows which are not attached to a host view.
1074 // The reordered layers are however positioned below any window layers with a
1075 // NULL delegate.
1076
1077 // Find all the child windows which are attached to a view.
1078 std::map<View*, aura::Window*> hosted_windows;
sky 2013/05/21 23:43:55 This method is long, break it up where you can. Fo
pkotwicz 2013/05/23 02:28:07 Done.
1079 const std::vector<aura::Window*>& child_windows = parent->children();
1080 for (size_t i = 0; i < child_windows.size(); ++i) {
1081 aura::Window* child = child_windows[i];
1082 View* host_view = child->GetProperty(kHostViewKey);
1083 if (host_view) {
1084 if (!child->layer()->delegate()) {
1085 // If there is a case where the attached NativeView has a NULL layer
1086 // delegate, we would need handle this case in View::ReorderChildView().
1087 NOTREACHED();
1088 }
1089
1090 hosted_windows[host_view] = child;
1091 }
1092 }
1093
sky 2013/05/21 23:43:55 Can't you early out if hosted_windows is empty?
pkotwicz 2013/05/23 02:28:07 We cannot early out here because there may be view
sky 2013/05/23 15:36:49 Why don't we change ReorderLayers/ReorderChildLaye
pkotwicz 2013/05/23 17:21:45 The change you are suggesting would result in chan
sky 2013/05/23 17:33:35 I think that better matches expectations, right? R
1094 // Compute the desired z-order of the layers based on the order of the views
1095 // with layers and views with attached windows in the view tree.
1096 std::vector<View*> view_with_layer_order;
1097 {
1098 // Temporarily modify the ids of the views attached to a window to simplify
sky 2013/05/21 23:43:55 Yuck! Don't muck with the ids like this.
pkotwicz 2013/05/23 02:28:07 No more modifying of the ids
1099 // GetOrderOfViewsWithLayers.
1100 const int kHostViewId = 1;
1101 std::map<View*, int> old_ids;
1102 for (std::map<View*, aura::Window*>::iterator it = hosted_windows.begin();
1103 it != hosted_windows.end(); ++it) {
1104 View* v = it->first;
1105 old_ids[v] = v->id();
1106 v->set_id(kHostViewId);
1107 }
1108
1109 GetOrderOfViewsWithLayers(root_view, parent->layer(), kHostViewId,
1110 hosted_windows, &view_with_layer_order);
1111
1112 // Reset the view ids.
1113 for (std::map<View*, int>::iterator it = old_ids.begin();
1114 it != old_ids.end(); ++it) {
1115 it->first->set_id(it->second);
1116 }
1117 }
1118
1119 // Find the bottommost window with a NULL layer delegate below which the
1120 // reordered layers should be stacked. |stack_below_window| should be NULL
1121 // if the reodered layers should be stacked at the top.
1122 aura::Window* stack_below_window = NULL;
1123 for (size_t i = 0; i < child_windows.size(); ++i) {
1124 aura::Window* child = child_windows[i];
1125 if (!child->layer()->delegate()) {
1126 stack_below_window = child;
1127 break;
1128 }
1129 }
1130
1131 // Reorder the layers and windows.
1132 for (size_t i = 0; i < view_with_layer_order.size(); ++i) {
1133 View* view = view_with_layer_order[i];
1134 ui::Layer* layer = view->layer();
1135 aura::Window* window = NULL;
1136
1137 std::map<View*, aura::Window*>::iterator hosted_window_it =
1138 hosted_windows.find(view);
1139 if (hosted_window_it != hosted_windows.end()) {
1140 window = hosted_window_it->second;
1141 layer = window->layer();
1142 }
1143
1144 DCHECK(layer);
1145 if (stack_below_window) {
1146 if (window)
1147 parent->StackChildBelow(window, stack_below_window);
1148 parent->layer()->StackBelow(layer, stack_below_window->layer());
1149 } else {
1150 if (window)
1151 parent->StackChildAtTop(window);
1152 parent->layer()->StackAtTop(layer);
1153 }
1154 }
1155 }
1156
1157 // static
1034 bool NativeWidgetPrivate::IsMouseButtonDown() { 1158 bool NativeWidgetPrivate::IsMouseButtonDown() {
1035 return aura::Env::GetInstance()->is_mouse_button_down(); 1159 return aura::Env::GetInstance()->is_mouse_button_down();
1036 } 1160 }
1037 1161
1038 // static 1162 // static
1039 bool NativeWidgetPrivate::IsTouchDown() { 1163 bool NativeWidgetPrivate::IsTouchDown() {
1040 return aura::Env::GetInstance()->is_touch_down(); 1164 return aura::Env::GetInstance()->is_touch_down();
1041 } 1165 }
1042 1166
1043 } // namespace internal 1167 } // namespace internal
1044 } // namespace views 1168 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/views.gyp ('k') | ui/views/widget/native_widget_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698