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

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

Issue 6881107: Rework the way Widget::Init works: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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_win.h ('k') | views/widget/widget_win_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) 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_win.h" 5 #include "views/widget/widget_win.h"
6 6
7 #include <dwmapi.h> 7 #include <dwmapi.h>
8 8
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/win/windows_version.h" 10 #include "base/win/windows_version.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 it != accessibility_view_events_.end(); 187 it != accessibility_view_events_.end();
188 ++it) { 188 ++it) {
189 if (*it == view) 189 if (*it == view)
190 *it = NULL; 190 *it = NULL;
191 } 191 }
192 } 192 }
193 193
194 //////////////////////////////////////////////////////////////////////////////// 194 ////////////////////////////////////////////////////////////////////////////////
195 // WidgetWin, Widget implementation: 195 // WidgetWin, Widget implementation:
196 196
197 void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) {
198 Widget::Init(parent, bounds);
199
200 // Create the window.
201 WindowImpl::Init(parent, bounds);
202 }
203
204 void WidgetWin::InitWithWidget(Widget* parent, const gfx::Rect& bounds) {
205 Init(parent->GetNativeView(), bounds);
206 }
207
208 gfx::NativeView WidgetWin::GetNativeView() const { 197 gfx::NativeView WidgetWin::GetNativeView() const {
209 return WindowImpl::hwnd(); 198 return WindowImpl::hwnd();
210 } 199 }
211 200
212 bool WidgetWin::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { 201 bool WidgetWin::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) {
213 return false; 202 return false;
214 } 203 }
215 204
216 Window* WidgetWin::GetWindow() { 205 Window* WidgetWin::GetWindow() {
217 return GetWindowImpl(hwnd()); 206 return GetWindowImpl(hwnd());
218 } 207 }
219 208
220 const Window* WidgetWin::GetWindow() const { 209 const Window* WidgetWin::GetWindow() const {
221 return GetWindowImpl(hwnd()); 210 return GetWindowImpl(hwnd());
222 } 211 }
223 212
224 void WidgetWin::ViewHierarchyChanged(bool is_add, View* parent, 213 void WidgetWin::ViewHierarchyChanged(bool is_add, View* parent,
225 View* child) { 214 View* child) {
226 Widget::ViewHierarchyChanged(is_add, parent, child); 215 Widget::ViewHierarchyChanged(is_add, parent, child);
227 if (drop_target_.get()) 216 if (drop_target_.get())
228 drop_target_->ResetTargetViewIfEquals(child); 217 drop_target_->ResetTargetViewIfEquals(child);
229 218
230 if (!is_add) 219 if (!is_add)
231 ClearAccessibilityViewEvent(child); 220 ClearAccessibilityViewEvent(child);
232 } 221 }
233 222
234 //////////////////////////////////////////////////////////////////////////////// 223 ////////////////////////////////////////////////////////////////////////////////
235 // WidgetWin, NativeWidget implementation: 224 // WidgetWin, NativeWidget implementation:
236 225
237 void WidgetWin::SetCreateParams(const CreateParams& params) { 226 void WidgetWin::InitNativeWidget(const Widget::CreateParams& params) {
238 DCHECK(!GetNativeView()); 227 SetCreateParams(params);
239 228
240 // Set non-style attributes. 229 // Create the window.
241 delete_on_destroy_ = params.delete_on_destroy; 230 gfx::NativeView parent = params.parent_widget ?
242 231 params.parent_widget->GetNativeView() : params.parent;
243 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; 232 WindowImpl::Init(parent, params.bounds);
244 DWORD ex_style = 0;
245 DWORD class_style = CS_DBLCLKS;
246
247 // Set type-independent style attributes.
248 if (params.child)
249 style |= WS_CHILD | WS_VISIBLE;
250 if (!params.accept_events)
251 ex_style |= WS_EX_TRANSPARENT;
252 if (!params.can_activate)
253 ex_style |= WS_EX_NOACTIVATE;
254 if (params.keep_on_top)
255 ex_style |= WS_EX_TOPMOST;
256 if (params.mirror_origin_in_rtl)
257 ex_style |= l10n_util::GetExtendedTooltipStyles();
258 if (params.transparent)
259 ex_style |= WS_EX_LAYERED;
260 if (params.has_dropshadow) {
261 class_style |= (base::win::GetVersion() < base::win::VERSION_XP) ?
262 0 : CS_DROPSHADOW;
263 }
264
265 // Set type-dependent style attributes.
266 switch (params.type) {
267 case CreateParams::TYPE_WINDOW:
268 case CreateParams::TYPE_CONTROL:
269 break;
270 case CreateParams::TYPE_POPUP:
271 style |= WS_POPUP;
272 ex_style |= WS_EX_TOOLWINDOW;
273 break;
274 case CreateParams::TYPE_MENU:
275 style |= WS_POPUP;
276 is_mouse_button_pressed_ =
277 ((GetKeyState(VK_LBUTTON) & 0x80) ||
278 (GetKeyState(VK_RBUTTON) & 0x80) ||
279 (GetKeyState(VK_MBUTTON) & 0x80) ||
280 (GetKeyState(VK_XBUTTON1) & 0x80) ||
281 (GetKeyState(VK_XBUTTON2) & 0x80));
282 break;
283 default:
284 NOTREACHED();
285 }
286
287 set_initial_class_style(class_style);
288 set_window_style(style);
289 set_window_ex_style(ex_style);
290 } 233 }
291 234
292 Widget* WidgetWin::GetWidget() { 235 Widget* WidgetWin::GetWidget() {
293 return this; 236 return this;
294 } 237 }
295 238
296 void WidgetWin::SetNativeWindowProperty(const char* name, void* value) { 239 void WidgetWin::SetNativeWindowProperty(const char* name, void* value) {
297 // Remove the existing property (if any). 240 // Remove the existing property (if any).
298 for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) { 241 for (ViewProps::iterator i = props_.begin(); i != props_.end(); ++i) {
299 if ((*i)->Key() == name) { 242 if ((*i)->Key() == name) {
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 } 1059 }
1117 1060
1118 void WidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) { 1061 void WidgetWin::DispatchKeyEventPostIME(const KeyEvent& key) {
1119 SetMsgHandled(delegate_->OnKeyEvent(key)); 1062 SetMsgHandled(delegate_->OnKeyEvent(key));
1120 } 1063 }
1121 1064
1122 //////////////////////////////////////////////////////////////////////////////// 1065 ////////////////////////////////////////////////////////////////////////////////
1123 // Widget, public: 1066 // Widget, public:
1124 1067
1125 // static 1068 // static
1126 Widget* Widget::CreateWidget(const CreateParams& params) { 1069 Widget* Widget::CreateWidget() {
1127 WidgetWin* widget = new WidgetWin; 1070 return new WidgetWin;
1128 widget->SetCreateParams(params);
1129 return widget;
1130 } 1071 }
1131 1072
1132 // static 1073 // static
1133 void Widget::NotifyLocaleChanged() { 1074 void Widget::NotifyLocaleChanged() {
1134 NOTIMPLEMENTED(); 1075 NOTIMPLEMENTED();
1135 } 1076 }
1136 1077
1137 bool Widget::ConvertRect(const Widget* source, 1078 bool Widget::ConvertRect(const Widget* source,
1138 const Widget* target, 1079 const Widget* target,
1139 gfx::Rect* rect) { 1080 gfx::Rect* rect) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 1177
1237 // And now, notify them that they have a brand new parent. 1178 // And now, notify them that they have a brand new parent.
1238 for (NativeWidgets::iterator it = widgets.begin(); 1179 for (NativeWidgets::iterator it = widgets.begin();
1239 it != widgets.end(); ++it) { 1180 it != widgets.end(); ++it) {
1240 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, 1181 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true,
1241 new_parent); 1182 new_parent);
1242 } 1183 }
1243 } 1184 }
1244 1185
1245 } // namespace views 1186 } // namespace views
OLDNEW
« no previous file with comments | « views/widget/widget_win.h ('k') | views/widget/widget_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698