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

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

Issue 6623025: Make more methods on Widget non-virtual and move to NativeWidget... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | « views/widget/widget.h ('k') | views/widget/widget_gtk.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/widget/widget.h" 5 #include "views/widget/widget.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "views/focus/view_storage.h" 9 #include "views/focus/view_storage.h"
10 #include "views/widget/default_theme_provider.h" 10 #include "views/widget/default_theme_provider.h"
11 #include "views/widget/root_view.h" 11 #include "views/widget/root_view.h"
12 #include "views/widget/native_widget.h" 12 #include "views/widget/native_widget.h"
13 13
14 namespace views { 14 namespace views {
15 15
16 //////////////////////////////////////////////////////////////////////////////// 16 ////////////////////////////////////////////////////////////////////////////////
17 // Widget, public: 17 // Widget, public:
18 18
19 Widget::Widget() 19 Widget::Widget()
20 : native_widget_(NULL), 20 : native_widget_(NULL),
21 widget_delegate_(NULL), 21 widget_delegate_(NULL),
22 dragged_view_(NULL) { 22 dragged_view_(NULL) {
23 } 23 }
24 24
25 Widget::~Widget() { 25 Widget::~Widget() {
26 } 26 }
27 27
28 // Unconverted methods (see header) --------------------------------------------
29
28 void Widget::Init(gfx::NativeView parent, const gfx::Rect& bounds) { 30 void Widget::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
29 GetRootView(); 31 GetRootView();
30 default_theme_provider_.reset(new DefaultThemeProvider); 32 default_theme_provider_.reset(new DefaultThemeProvider);
31 } 33 }
32 34
33 void Widget::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { 35 void Widget::InitWithWidget(Widget* parent, const gfx::Rect& bounds) {
34 } 36 }
35 37
38 gfx::NativeView Widget::GetNativeView() const {
39 return NULL;
40 }
41
42 void Widget::GenerateMousePressedForView(View* view, const gfx::Point& point) {
43 }
44
45 bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) {
46 return false;
47 }
48
49 Window* Widget::GetWindow() {
50 return NULL;
51 }
52
53 const Window* Widget::GetWindow() const {
54 return NULL;
55 }
56
57 void Widget::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
58 if (!is_add) {
59 if (child == dragged_view_)
60 dragged_view_ = NULL;
61
62 FocusManager* focus_manager = GetFocusManager();
63 if (focus_manager) {
64 if (focus_manager->GetFocusedView() == child)
65 focus_manager->SetFocusedView(NULL);
66 focus_manager->ViewRemoved(parent, child);
67 }
68 ViewStorage::GetInstance()->ViewRemoved(parent, child);
69 }
70 }
71
72 // Converted methods (see header) ----------------------------------------------
73
36 Widget* Widget::GetTopLevelWidget() { 74 Widget* Widget::GetTopLevelWidget() {
37 return const_cast<Widget*>( 75 return const_cast<Widget*>(
38 const_cast<const Widget*>(this)->GetTopLevelWidget()); 76 const_cast<const Widget*>(this)->GetTopLevelWidget());
39 } 77 }
40 78
41 const Widget* Widget::GetTopLevelWidget() const { 79 const Widget* Widget::GetTopLevelWidget() const {
42 NativeWidget* native_widget = 80 NativeWidget* native_widget =
43 NativeWidget::GetTopLevelNativeWidget(GetNativeView()); 81 NativeWidget::GetTopLevelNativeWidget(GetNativeView());
44 return native_widget ? native_widget->GetWidget() : NULL; 82 return native_widget ? native_widget->GetWidget() : NULL;
45 } 83 }
46 84
47 void Widget::SetContentsView(View* view) { 85 void Widget::SetContentsView(View* view) {
48 root_view_->SetContentsView(view); 86 root_view_->SetContentsView(view);
49 } 87 }
50 88
51 gfx::Rect Widget::GetWindowScreenBounds() const { 89 gfx::Rect Widget::GetWindowScreenBounds() const {
52 return native_widget_->GetWindowScreenBounds(); 90 return native_widget_->GetWindowScreenBounds();
53 } 91 }
54 92
55 gfx::Rect Widget::GetClientAreaScreenBounds() const { 93 gfx::Rect Widget::GetClientAreaScreenBounds() const {
56 return native_widget_->GetClientAreaScreenBounds(); 94 return native_widget_->GetClientAreaScreenBounds();
57 } 95 }
58 96
59 void Widget::SetBounds(const gfx::Rect& bounds) { 97 void Widget::SetBounds(const gfx::Rect& bounds) {
98 native_widget_->SetBounds(bounds);
60 } 99 }
61 100
62 void Widget::MoveAbove(Widget* widget) { 101 void Widget::MoveAbove(Widget* widget) {
102 native_widget_->MoveAbove(widget);
63 } 103 }
64 104
65 void Widget::SetShape(gfx::NativeRegion shape) { 105 void Widget::SetShape(gfx::NativeRegion shape) {
106 native_widget_->SetShape(shape);
66 } 107 }
67 108
68 void Widget::Close() { 109 void Widget::Close() {
110 native_widget_->Close();
69 } 111 }
70 112
71 void Widget::CloseNow() { 113 void Widget::CloseNow() {
114 native_widget_->CloseNow();
72 } 115 }
73 116
74 void Widget::Show() { 117 void Widget::Show() {
118 native_widget_->Show();
75 } 119 }
76 120
77 void Widget::Hide() { 121 void Widget::Hide() {
78 } 122 native_widget_->Hide();
79
80 gfx::NativeView Widget::GetNativeView() const {
81 return NULL;
82 } 123 }
83 124
84 void Widget::SetOpacity(unsigned char opacity) { 125 void Widget::SetOpacity(unsigned char opacity) {
126 native_widget_->SetOpacity(opacity);
85 } 127 }
86 128
87 void Widget::SetAlwaysOnTop(bool on_top) { 129 void Widget::SetAlwaysOnTop(bool on_top) {
130 native_widget_->SetAlwaysOnTop(on_top);
88 } 131 }
89 132
90 RootView* Widget::GetRootView() { 133 RootView* Widget::GetRootView() {
91 if (!root_view_.get()) { 134 if (!root_view_.get()) {
92 // First time the root view is being asked for, create it now. 135 // First time the root view is being asked for, create it now.
93 root_view_.reset(CreateRootView()); 136 root_view_.reset(CreateRootView());
94 } 137 }
95 return root_view_.get(); 138 return root_view_.get();
96 } 139 }
97 140
98 bool Widget::IsVisible() const { 141 bool Widget::IsVisible() const {
99 return false; 142 return native_widget_->IsVisible();
100 } 143 }
101 144
102 bool Widget::IsActive() const { 145 bool Widget::IsActive() const {
103 return false; 146 return native_widget_->IsActive();
104 } 147 }
105 148
106 bool Widget::IsAccessibleWidget() const { 149 bool Widget::IsAccessibleWidget() const {
107 return false; 150 return native_widget_->IsAccessibleWidget();
108 }
109
110 void Widget::GenerateMousePressedForView(View* view, const gfx::Point& point) {
111 }
112
113 bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) {
114 return false;
115 }
116
117 Window* Widget::GetWindow() {
118 return NULL;
119 }
120
121 const Window* Widget::GetWindow() const {
122 return NULL;
123 } 151 }
124 152
125 ThemeProvider* Widget::GetThemeProvider() const { 153 ThemeProvider* Widget::GetThemeProvider() const {
126 const Widget* root_widget = GetTopLevelWidget(); 154 const Widget* root_widget = GetTopLevelWidget();
127 if (root_widget && root_widget != this) { 155 if (root_widget && root_widget != this) {
128 // Attempt to get the theme provider, and fall back to the default theme 156 // Attempt to get the theme provider, and fall back to the default theme
129 // provider if not found. 157 // provider if not found.
130 ThemeProvider* provider = root_widget->GetThemeProvider(); 158 ThemeProvider* provider = root_widget->GetThemeProvider();
131 if (provider) 159 if (provider)
132 return provider; 160 return provider;
133 161
134 provider = root_widget->default_theme_provider_.get(); 162 provider = root_widget->default_theme_provider_.get();
135 if (provider) 163 if (provider)
136 return provider; 164 return provider;
137 } 165 }
138 return default_theme_provider_.get(); 166 return default_theme_provider_.get();
139 } 167 }
140 168
141 FocusManager* Widget::GetFocusManager() { 169 FocusManager* Widget::GetFocusManager() {
142 Widget* toplevel_widget = GetTopLevelWidget(); 170 Widget* toplevel_widget = GetTopLevelWidget();
143 if (toplevel_widget && toplevel_widget != this) 171 if (toplevel_widget && toplevel_widget != this)
144 return toplevel_widget->focus_manager_.get(); 172 return toplevel_widget->focus_manager_.get();
145 173
146 return focus_manager_.get(); 174 return focus_manager_.get();
147 } 175 }
148 176
149 void Widget::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
150 if (!is_add) {
151 if (child == dragged_view_)
152 dragged_view_ = NULL;
153
154 FocusManager* focus_manager = GetFocusManager();
155 if (focus_manager) {
156 if (focus_manager->GetFocusedView() == child)
157 focus_manager->SetFocusedView(NULL);
158 focus_manager->ViewRemoved(parent, child);
159 }
160 ViewStorage::GetInstance()->ViewRemoved(parent, child);
161 }
162 }
163
164 bool Widget::ContainsNativeView(gfx::NativeView native_view) { 177 bool Widget::ContainsNativeView(gfx::NativeView native_view) {
165 if (native_widget_->ContainsNativeView(native_view)) 178 if (native_widget_->ContainsNativeView(native_view))
166 return true; 179 return true;
167 180
168 // A views::NativeViewHost may contain the given native view, without it being 181 // A views::NativeViewHost may contain the given native view, without it being
169 // an ancestor of hwnd(), so traverse the views::View hierarchy looking for 182 // an ancestor of hwnd(), so traverse the views::View hierarchy looking for
170 // such views. 183 // such views.
171 return GetRootView()->ContainsNativeView(native_view); 184 return GetRootView()->ContainsNativeView(native_view);
172 } 185 }
173 186
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 FocusManager* focus_manager = focus_manager_.release(); 296 FocusManager* focus_manager = focus_manager_.release();
284 if (focus_manager) 297 if (focus_manager)
285 MessageLoop::current()->DeleteSoon(FROM_HERE, focus_manager); 298 MessageLoop::current()->DeleteSoon(FROM_HERE, focus_manager);
286 } 299 }
287 300
288 void Widget::ReplaceFocusManager(FocusManager* focus_manager) { 301 void Widget::ReplaceFocusManager(FocusManager* focus_manager) {
289 focus_manager_.reset(focus_manager); 302 focus_manager_.reset(focus_manager);
290 } 303 }
291 304
292 } // namespace views 305 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/widget.h ('k') | views/widget/widget_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698