| 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.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 "ui/gfx/compositor/compositor.h" | 9 #include "ui/gfx/compositor/compositor.h" |
| 10 #include "views/focus/view_storage.h" | 10 #include "views/focus/view_storage.h" |
| 11 #include "views/ime/input_method.h" | 11 #include "views/ime/input_method.h" |
| 12 #include "views/views_delegate.h" |
| 12 #include "views/widget/default_theme_provider.h" | 13 #include "views/widget/default_theme_provider.h" |
| 13 #include "views/widget/root_view.h" | 14 #include "views/widget/root_view.h" |
| 14 #include "views/widget/native_widget.h" | 15 #include "views/widget/native_widget.h" |
| 15 | 16 |
| 16 namespace views { | 17 namespace views { |
| 17 | 18 |
| 18 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
| 19 // Widget, InitParams: | 20 // Widget, InitParams: |
| 20 | 21 |
| 21 Widget::InitParams::InitParams() | 22 Widget::InitParams::InitParams() |
| 22 : type(TYPE_WINDOW), | 23 : type(TYPE_WINDOW), |
| 23 child(false), | 24 child(false), |
| 25 transient(false), |
| 24 transparent(false), | 26 transparent(false), |
| 25 accept_events(true), | 27 accept_events(true), |
| 26 can_activate(true), | 28 can_activate(true), |
| 27 keep_on_top(false), | 29 keep_on_top(false), |
| 28 delete_on_destroy(true), | 30 delete_on_destroy(true), |
| 29 mirror_origin_in_rtl(false), | 31 mirror_origin_in_rtl(false), |
| 30 has_dropshadow(false), | 32 has_dropshadow(false), |
| 31 double_buffer(false), | 33 double_buffer(false), |
| 32 parent(NULL), | 34 parent(NULL), |
| 33 parent_widget(NULL), | 35 parent_widget(NULL), |
| 34 native_widget(NULL) { | 36 native_widget(NULL) { |
| 35 } | 37 } |
| 36 | 38 |
| 37 Widget::InitParams::InitParams(Type type) | 39 Widget::InitParams::InitParams(Type type) |
| 38 : type(type), | 40 : type(type), |
| 39 child(type == TYPE_CONTROL), | 41 child(type == TYPE_CONTROL), |
| 42 transient(type == TYPE_POPUP || type == TYPE_MENU), |
| 40 transparent(false), | 43 transparent(false), |
| 41 accept_events(true), | 44 accept_events(true), |
| 42 can_activate(type != TYPE_POPUP && type != TYPE_MENU), | 45 can_activate(type != TYPE_POPUP && type != TYPE_MENU), |
| 43 keep_on_top(type == TYPE_MENU), | 46 keep_on_top(type == TYPE_MENU), |
| 44 delete_on_destroy(true), | 47 delete_on_destroy(true), |
| 45 mirror_origin_in_rtl(false), | 48 mirror_origin_in_rtl(false), |
| 46 has_dropshadow(false), | 49 has_dropshadow(false), |
| 47 double_buffer(false), | 50 double_buffer(false), |
| 48 parent(NULL), | 51 parent(NULL), |
| 49 parent_widget(NULL), | 52 parent_widget(NULL), |
| 50 native_widget(NULL) { | 53 native_widget(NULL) { |
| 51 } | 54 } |
| 52 | 55 |
| 53 //////////////////////////////////////////////////////////////////////////////// | 56 //////////////////////////////////////////////////////////////////////////////// |
| 54 // Widget, public: | 57 // Widget, public: |
| 55 | 58 |
| 56 // static | 59 // static |
| 57 Widget::InitParams Widget::WindowInitParams() { | 60 Widget::InitParams Widget::WindowInitParams() { |
| 58 return InitParams(InitParams::TYPE_WINDOW); | 61 return InitParams(InitParams::TYPE_WINDOW); |
| 59 } | 62 } |
| 60 | 63 |
| 61 Widget::Widget() | 64 Widget::Widget() |
| 62 : is_mouse_button_pressed_(false), | 65 : is_mouse_button_pressed_(false), |
| 63 last_mouse_event_was_move_(false), | 66 last_mouse_event_was_move_(false), |
| 64 native_widget_(NULL), | 67 native_widget_(NULL), |
| 65 widget_delegate_(NULL), | 68 widget_delegate_(NULL), |
| 66 dragged_view_(NULL) { | 69 dragged_view_(NULL), |
| 70 delete_on_destroy_(false), |
| 71 is_secondary_widget_(true) { |
| 67 } | 72 } |
| 68 | 73 |
| 69 Widget::~Widget() { | 74 Widget::~Widget() { |
| 75 DestroyRootView(); |
| 76 |
| 77 if (!delete_on_destroy_) |
| 78 delete native_widget_; |
| 70 } | 79 } |
| 71 | 80 |
| 72 void Widget::Init(const InitParams& params) { | 81 void Widget::Init(const InitParams& params) { |
| 82 delete_on_destroy_ = params.delete_on_destroy; |
| 83 native_widget_ = |
| 84 params.native_widget ? params.native_widget |
| 85 : NativeWidget::CreateNativeWidget(this); |
| 73 GetRootView(); | 86 GetRootView(); |
| 74 default_theme_provider_.reset(new DefaultThemeProvider); | 87 default_theme_provider_.reset(new DefaultThemeProvider); |
| 88 if (params.type == InitParams::TYPE_MENU) |
| 89 is_mouse_button_pressed_ = native_widget_->IsMouseButtonDown(); |
| 75 native_widget_->InitNativeWidget(params); | 90 native_widget_->InitNativeWidget(params); |
| 76 } | 91 } |
| 77 | 92 |
| 78 // Unconverted methods (see header) -------------------------------------------- | 93 // Unconverted methods (see header) -------------------------------------------- |
| 79 | 94 |
| 80 gfx::NativeView Widget::GetNativeView() const { | 95 gfx::NativeView Widget::GetNativeView() const { |
| 81 return NULL; | 96 return native_widget_->GetNativeView(); |
| 82 } | 97 } |
| 83 | 98 |
| 84 gfx::NativeWindow Widget::GetNativeWindow() const { | 99 gfx::NativeWindow Widget::GetNativeWindow() const { |
| 85 return NULL; | 100 return native_widget_->GetNativeWindow(); |
| 86 } | |
| 87 | |
| 88 void Widget::GenerateMousePressedForView(View* view, const gfx::Point& point) { | |
| 89 } | 101 } |
| 90 | 102 |
| 91 bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { | 103 bool Widget::GetAccelerator(int cmd_id, ui::Accelerator* accelerator) { |
| 92 return false; | 104 return false; |
| 93 } | 105 } |
| 94 | 106 |
| 95 Window* Widget::GetWindow() { | 107 Window* Widget::GetContainingWindow() { |
| 96 return NULL; | 108 return native_widget_->GetContainingWindow(); |
| 97 } | 109 } |
| 98 | 110 |
| 99 const Window* Widget::GetWindow() const { | 111 const Window* Widget::GetContainingWindow() const { |
| 100 return NULL; | 112 return native_widget_->GetContainingWindow(); |
| 101 } | 113 } |
| 102 | 114 |
| 103 void Widget::ViewHierarchyChanged(bool is_add, View* parent, View* child) { | 115 void Widget::ViewHierarchyChanged(bool is_add, View* parent, View* child) { |
| 104 if (!is_add) { | 116 if (!is_add) { |
| 105 if (child == dragged_view_) | 117 if (child == dragged_view_) |
| 106 dragged_view_ = NULL; | 118 dragged_view_ = NULL; |
| 107 | 119 |
| 108 FocusManager* focus_manager = GetFocusManager(); | 120 FocusManager* focus_manager = GetFocusManager(); |
| 109 if (focus_manager) | 121 if (focus_manager) |
| 110 focus_manager->ViewRemoved(child); | 122 focus_manager->ViewRemoved(child); |
| 111 ViewStorage::GetInstance()->ViewRemoved(parent, child); | 123 ViewStorage::GetInstance()->ViewRemoved(child); |
| 124 native_widget_->ViewRemoved(child); |
| 112 } | 125 } |
| 113 } | 126 } |
| 114 | 127 |
| 115 void Widget::NotifyNativeViewHierarchyChanged(bool attached, | 128 void Widget::NotifyNativeViewHierarchyChanged(bool attached, |
| 116 gfx::NativeView native_view) { | 129 gfx::NativeView native_view) { |
| 117 if (!attached) { | 130 if (!attached) { |
| 118 FocusManager* focus_manager = GetFocusManager(); | 131 FocusManager* focus_manager = GetFocusManager(); |
| 119 // We are being removed from a window hierarchy. Treat this as | 132 // We are being removed from a window hierarchy. Treat this as |
| 120 // the root_view_ being removed. | 133 // the root_view_ being removed. |
| 121 if (focus_manager) | 134 if (focus_manager) |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 279 } |
| 267 | 280 |
| 268 void Widget::SchedulePaintInRect(const gfx::Rect& rect) { | 281 void Widget::SchedulePaintInRect(const gfx::Rect& rect) { |
| 269 native_widget_->SchedulePaintInRect(rect); | 282 native_widget_->SchedulePaintInRect(rect); |
| 270 } | 283 } |
| 271 | 284 |
| 272 void Widget::SetCursor(gfx::NativeCursor cursor) { | 285 void Widget::SetCursor(gfx::NativeCursor cursor) { |
| 273 native_widget_->SetCursor(cursor); | 286 native_widget_->SetCursor(cursor); |
| 274 } | 287 } |
| 275 | 288 |
| 289 void Widget::ResetLastMouseMoveFlag() { |
| 290 last_mouse_event_was_move_ = false; |
| 291 } |
| 292 |
| 276 FocusTraversable* Widget::GetFocusTraversable() { | 293 FocusTraversable* Widget::GetFocusTraversable() { |
| 277 return root_view_.get(); | 294 return root_view_.get(); |
| 278 } | 295 } |
| 279 | 296 |
| 280 void Widget::ThemeChanged() { | 297 void Widget::ThemeChanged() { |
| 281 root_view_->ThemeChanged(); | 298 root_view_->ThemeChanged(); |
| 282 } | 299 } |
| 283 | 300 |
| 284 void Widget::LocaleChanged() { | 301 void Widget::LocaleChanged() { |
| 285 root_view_->LocaleChanged(); | 302 root_view_->LocaleChanged(); |
| 286 } | 303 } |
| 287 | 304 |
| 288 void Widget::SetFocusTraversableParent(FocusTraversable* parent) { | 305 void Widget::SetFocusTraversableParent(FocusTraversable* parent) { |
| 289 root_view_->SetFocusTraversableParent(parent); | 306 root_view_->SetFocusTraversableParent(parent); |
| 290 } | 307 } |
| 291 | 308 |
| 292 void Widget::SetFocusTraversableParentView(View* parent_view) { | 309 void Widget::SetFocusTraversableParentView(View* parent_view) { |
| 293 root_view_->SetFocusTraversableParentView(parent_view); | 310 root_view_->SetFocusTraversableParentView(parent_view); |
| 294 } | 311 } |
| 295 | 312 |
| 313 void Widget::NotifyAccessibilityEvent( |
| 314 View* view, |
| 315 ui::AccessibilityTypes::Event event_type, |
| 316 bool send_native_event) { |
| 317 // Send the notification to the delegate. |
| 318 if (ViewsDelegate::views_delegate) |
| 319 ViewsDelegate::views_delegate->NotifyAccessibilityEvent(view, event_type); |
| 320 |
| 321 if (send_native_event) |
| 322 native_widget_->SendNativeAccessibilityEvent(view, event_type); |
| 323 } |
| 324 |
| 296 //////////////////////////////////////////////////////////////////////////////// | 325 //////////////////////////////////////////////////////////////////////////////// |
| 297 // Widget, NativeWidgetDelegate implementation: | 326 // Widget, NativeWidgetDelegate implementation: |
| 298 | 327 |
| 299 void Widget::OnNativeFocus(gfx::NativeView focused_view) { | 328 void Widget::OnNativeFocus(gfx::NativeView focused_view) { |
| 300 GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent( | 329 GetFocusManager()->GetWidgetFocusManager()->OnWidgetFocusEvent( |
| 301 focused_view, | 330 focused_view, |
| 302 GetNativeView()); | 331 GetNativeView()); |
| 303 } | 332 } |
| 304 | 333 |
| 305 void Widget::OnNativeBlur(gfx::NativeView focused_view) { | 334 void Widget::OnNativeBlur(gfx::NativeView focused_view) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 } | 429 } |
| 401 return true; | 430 return true; |
| 402 } | 431 } |
| 403 | 432 |
| 404 void Widget::OnMouseCaptureLost() { | 433 void Widget::OnMouseCaptureLost() { |
| 405 if (is_mouse_button_pressed_) | 434 if (is_mouse_button_pressed_) |
| 406 GetRootView()->OnMouseCaptureLost(); | 435 GetRootView()->OnMouseCaptureLost(); |
| 407 is_mouse_button_pressed_ = false; | 436 is_mouse_button_pressed_ = false; |
| 408 } | 437 } |
| 409 | 438 |
| 439 Widget* Widget::AsWidget() { |
| 440 return this; |
| 441 } |
| 442 |
| 443 const Widget* Widget::AsWidget() const { |
| 444 return this; |
| 445 } |
| 446 |
| 410 //////////////////////////////////////////////////////////////////////////////// | 447 //////////////////////////////////////////////////////////////////////////////// |
| 411 // Widget, FocusTraversable implementation: | 448 // Widget, FocusTraversable implementation: |
| 412 | 449 |
| 413 FocusSearch* Widget::GetFocusSearch() { | 450 FocusSearch* Widget::GetFocusSearch() { |
| 414 return root_view_->GetFocusSearch(); | 451 return root_view_->GetFocusSearch(); |
| 415 } | 452 } |
| 416 | 453 |
| 417 FocusTraversable* Widget::GetFocusTraversableParent() { | 454 FocusTraversable* Widget::GetFocusTraversableParent() { |
| 418 // We are a proxy to the root view, so we should be bypassed when traversing | 455 // We are a proxy to the root view, so we should be bypassed when traversing |
| 419 // up and as a result this should not be called. | 456 // up and as a result this should not be called. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget(); | 502 gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget(); |
| 466 if (widget != gfx::kNullAcceleratedWidget) | 503 if (widget != gfx::kNullAcceleratedWidget) |
| 467 compositor_ = ui::Compositor::Create(widget); | 504 compositor_ = ui::Compositor::Create(widget); |
| 468 } | 505 } |
| 469 | 506 |
| 470 bool Widget::ShouldReleaseCaptureOnMouseReleased() const { | 507 bool Widget::ShouldReleaseCaptureOnMouseReleased() const { |
| 471 return true; | 508 return true; |
| 472 } | 509 } |
| 473 | 510 |
| 474 } // namespace views | 511 } // namespace views |
| OLD | NEW |