| OLD | NEW |
| 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 Loading... |
| 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 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 while (parent) { | 964 while (parent) { |
| 1022 WidgetWin* widget = | 965 WidgetWin* widget = |
| 1023 reinterpret_cast<WidgetWin*>(ui::GetWindowUserData(parent)); | 966 reinterpret_cast<WidgetWin*>(ui::GetWindowUserData(parent)); |
| 1024 if (widget && widget->is_window_) | 967 if (widget && widget->is_window_) |
| 1025 return static_cast<WindowWin*>(widget); | 968 return static_cast<WindowWin*>(widget); |
| 1026 parent = ::GetParent(parent); | 969 parent = ::GetParent(parent); |
| 1027 } | 970 } |
| 1028 return NULL; | 971 return NULL; |
| 1029 } | 972 } |
| 1030 | 973 |
| 974 void WidgetWin::SetCreateParams(const CreateParams& params) { |
| 975 // Set non-style attributes. |
| 976 delete_on_destroy_ = params.delete_on_destroy; |
| 977 |
| 978 DWORD style = WS_CLIPCHILDREN | WS_CLIPSIBLINGS; |
| 979 DWORD ex_style = 0; |
| 980 DWORD class_style = CS_DBLCLKS; |
| 981 |
| 982 // Set type-independent style attributes. |
| 983 if (params.child) |
| 984 style |= WS_CHILD | WS_VISIBLE; |
| 985 if (!params.accept_events) |
| 986 ex_style |= WS_EX_TRANSPARENT; |
| 987 if (!params.can_activate) |
| 988 ex_style |= WS_EX_NOACTIVATE; |
| 989 if (params.keep_on_top) |
| 990 ex_style |= WS_EX_TOPMOST; |
| 991 if (params.mirror_origin_in_rtl) |
| 992 ex_style |= l10n_util::GetExtendedTooltipStyles(); |
| 993 if (params.transparent) |
| 994 ex_style |= WS_EX_LAYERED; |
| 995 if (params.has_dropshadow) { |
| 996 class_style |= (base::win::GetVersion() < base::win::VERSION_XP) ? |
| 997 0 : CS_DROPSHADOW; |
| 998 } |
| 999 |
| 1000 // Set type-dependent style attributes. |
| 1001 switch (params.type) { |
| 1002 case CreateParams::TYPE_WINDOW: |
| 1003 case CreateParams::TYPE_CONTROL: |
| 1004 break; |
| 1005 case CreateParams::TYPE_POPUP: |
| 1006 style |= WS_POPUP; |
| 1007 ex_style |= WS_EX_TOOLWINDOW; |
| 1008 break; |
| 1009 case CreateParams::TYPE_MENU: |
| 1010 style |= WS_POPUP; |
| 1011 is_mouse_button_pressed_ = |
| 1012 ((GetKeyState(VK_LBUTTON) & 0x80) || |
| 1013 (GetKeyState(VK_RBUTTON) & 0x80) || |
| 1014 (GetKeyState(VK_MBUTTON) & 0x80) || |
| 1015 (GetKeyState(VK_XBUTTON1) & 0x80) || |
| 1016 (GetKeyState(VK_XBUTTON2) & 0x80)); |
| 1017 break; |
| 1018 default: |
| 1019 NOTREACHED(); |
| 1020 } |
| 1021 |
| 1022 set_initial_class_style(class_style); |
| 1023 set_window_style(window_style() | style); |
| 1024 set_window_ex_style(window_ex_style() | ex_style); |
| 1025 } |
| 1026 |
| 1031 RootView* WidgetWin::GetFocusedViewRootView() { | 1027 RootView* WidgetWin::GetFocusedViewRootView() { |
| 1032 // TODO(beng): get rid of this | 1028 // TODO(beng): get rid of this |
| 1033 FocusManager* focus_manager = GetFocusManager(); | 1029 FocusManager* focus_manager = GetFocusManager(); |
| 1034 if (!focus_manager) { | 1030 if (!focus_manager) { |
| 1035 NOTREACHED(); | 1031 NOTREACHED(); |
| 1036 return NULL; | 1032 return NULL; |
| 1037 } | 1033 } |
| 1038 View* focused_view = focus_manager->GetFocusedView(); | 1034 View* focused_view = focus_manager->GetFocusedView(); |
| 1039 if (!focused_view) | 1035 if (!focused_view) |
| 1040 return NULL; | 1036 return NULL; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 if (!root_view) | 1126 if (!root_view) |
| 1131 root_view = GetRootView(); | 1127 root_view = GetRootView(); |
| 1132 | 1128 |
| 1133 SetMsgHandled(root_view->ProcessKeyEvent(key)); | 1129 SetMsgHandled(root_view->ProcessKeyEvent(key)); |
| 1134 } | 1130 } |
| 1135 | 1131 |
| 1136 //////////////////////////////////////////////////////////////////////////////// | 1132 //////////////////////////////////////////////////////////////////////////////// |
| 1137 // Widget, public: | 1133 // Widget, public: |
| 1138 | 1134 |
| 1139 // static | 1135 // static |
| 1140 Widget* Widget::CreateWidget(const CreateParams& params) { | 1136 Widget* Widget::CreateWidget() { |
| 1141 WidgetWin* widget = new WidgetWin; | 1137 return new WidgetWin; |
| 1142 widget->SetCreateParams(params); | |
| 1143 return widget; | |
| 1144 } | 1138 } |
| 1145 | 1139 |
| 1146 // static | 1140 // static |
| 1147 void Widget::NotifyLocaleChanged() { | 1141 void Widget::NotifyLocaleChanged() { |
| 1148 NOTIMPLEMENTED(); | 1142 NOTIMPLEMENTED(); |
| 1149 } | 1143 } |
| 1150 | 1144 |
| 1151 bool Widget::ConvertRect(const Widget* source, | 1145 bool Widget::ConvertRect(const Widget* source, |
| 1152 const Widget* target, | 1146 const Widget* target, |
| 1153 gfx::Rect* rect) { | 1147 gfx::Rect* rect) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1250 | 1244 |
| 1251 // And now, notify them that they have a brand new parent. | 1245 // And now, notify them that they have a brand new parent. |
| 1252 for (NativeWidgets::iterator it = widgets.begin(); | 1246 for (NativeWidgets::iterator it = widgets.begin(); |
| 1253 it != widgets.end(); ++it) { | 1247 it != widgets.end(); ++it) { |
| 1254 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, | 1248 (*it)->GetWidget()->NotifyNativeViewHierarchyChanged(true, |
| 1255 new_parent); | 1249 new_parent); |
| 1256 } | 1250 } |
| 1257 } | 1251 } |
| 1258 | 1252 |
| 1259 } // namespace views | 1253 } // namespace views |
| OLD | NEW |