| OLD | NEW |
| 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/widget.h" | 5 #include "ui/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 "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "ui/base/event.h" |
| 10 #include "ui/base/hit_test.h" | 11 #include "ui/base/hit_test.h" |
| 11 #include "ui/base/l10n/l10n_font_util.h" | 12 #include "ui/base/l10n/l10n_font_util.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 13 #include "ui/compositor/compositor.h" | 14 #include "ui/compositor/compositor.h" |
| 14 #include "ui/compositor/layer.h" | 15 #include "ui/compositor/layer.h" |
| 15 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
| 16 #include "ui/views/focus/focus_manager.h" | 17 #include "ui/views/focus/focus_manager.h" |
| 17 #include "ui/views/focus/focus_manager_factory.h" | 18 #include "ui/views/focus/focus_manager_factory.h" |
| 18 #include "ui/views/focus/view_storage.h" | 19 #include "ui/views/focus/view_storage.h" |
| 19 #include "ui/views/focus/widget_focus_manager.h" | 20 #include "ui/views/focus/widget_focus_manager.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 48 } | 49 } |
| 49 | 50 |
| 50 } // namespace | 51 } // namespace |
| 51 | 52 |
| 52 // This class is used to keep track of the event a Widget is processing, and | 53 // This class is used to keep track of the event a Widget is processing, and |
| 53 // restore any previously active event afterwards. | 54 // restore any previously active event afterwards. |
| 54 class ScopedEvent { | 55 class ScopedEvent { |
| 55 public: | 56 public: |
| 56 ScopedEvent(Widget* widget, const Event& event) | 57 ScopedEvent(Widget* widget, const Event& event) |
| 57 : widget_(widget), | 58 : widget_(widget), |
| 58 event_(&event) { | 59 event_(&event), |
| 60 ui_event_(NULL) { |
| 61 widget->event_stack_.push(this); |
| 62 } |
| 63 ScopedEvent(Widget* widget, const ui::Event& ui_event) |
| 64 : widget_(widget), |
| 65 event_(NULL), |
| 66 ui_event_(&ui_event) { |
| 59 widget->event_stack_.push(this); | 67 widget->event_stack_.push(this); |
| 60 } | 68 } |
| 61 | 69 |
| 62 ~ScopedEvent() { | 70 ~ScopedEvent() { |
| 63 if (widget_) | 71 if (widget_) |
| 64 widget_->event_stack_.pop(); | 72 widget_->event_stack_.pop(); |
| 65 } | 73 } |
| 66 | 74 |
| 67 void reset() { | 75 void reset() { |
| 68 widget_ = NULL; | 76 widget_ = NULL; |
| 69 } | 77 } |
| 70 | 78 |
| 71 const Event* event() { | 79 const Event* event() { |
| 72 return event_; | 80 return event_; |
| 73 } | 81 } |
| 82 const ui::Event* ui_event() { |
| 83 return ui_event_; |
| 84 } |
| 74 | 85 |
| 75 private: | 86 private: |
| 76 Widget* widget_; | 87 Widget* widget_; |
| 77 const Event* event_; | 88 const Event* event_; |
| 89 // TODO(beng): remove once views::Event is gone. |
| 90 const ui::Event* ui_event_; |
| 78 | 91 |
| 79 DISALLOW_COPY_AND_ASSIGN(ScopedEvent); | 92 DISALLOW_COPY_AND_ASSIGN(ScopedEvent); |
| 80 }; | 93 }; |
| 81 | 94 |
| 82 // A default implementation of WidgetDelegate, used by Widget when no | 95 // A default implementation of WidgetDelegate, used by Widget when no |
| 83 // WidgetDelegate is supplied. | 96 // WidgetDelegate is supplied. |
| 84 class DefaultWidgetDelegate : public WidgetDelegate { | 97 class DefaultWidgetDelegate : public WidgetDelegate { |
| 85 public: | 98 public: |
| 86 DefaultWidgetDelegate(Widget* widget, const Widget::InitParams& params) | 99 DefaultWidgetDelegate(Widget* widget, const Widget::InitParams& params) |
| 87 : widget_(widget), | 100 : widget_(widget), |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 void Widget::OnNativeWidgetPaint(gfx::Canvas* canvas) { | 1063 void Widget::OnNativeWidgetPaint(gfx::Canvas* canvas) { |
| 1051 GetRootView()->Paint(canvas); | 1064 GetRootView()->Paint(canvas); |
| 1052 } | 1065 } |
| 1053 | 1066 |
| 1054 int Widget::GetNonClientComponent(const gfx::Point& point) { | 1067 int Widget::GetNonClientComponent(const gfx::Point& point) { |
| 1055 return non_client_view_ ? | 1068 return non_client_view_ ? |
| 1056 non_client_view_->NonClientHitTest(point) : | 1069 non_client_view_->NonClientHitTest(point) : |
| 1057 HTNOWHERE; | 1070 HTNOWHERE; |
| 1058 } | 1071 } |
| 1059 | 1072 |
| 1060 bool Widget::OnKeyEvent(const KeyEvent& event) { | 1073 bool Widget::OnKeyEvent(const ui::KeyEvent& event) { |
| 1061 ScopedEvent scoped(this, event); | 1074 ScopedEvent scoped(this, event); |
| 1062 return static_cast<internal::RootView*>(GetRootView())->OnKeyEvent(event); | 1075 return static_cast<internal::RootView*>(GetRootView())->OnKeyEvent(event); |
| 1063 } | 1076 } |
| 1064 | 1077 |
| 1065 bool Widget::OnMouseEvent(const MouseEvent& event) { | 1078 bool Widget::OnMouseEvent(const MouseEvent& event) { |
| 1066 ScopedEvent scoped(this, event); | 1079 ScopedEvent scoped(this, event); |
| 1067 switch (event.type()) { | 1080 switch (event.type()) { |
| 1068 case ui::ET_MOUSE_PRESSED: | 1081 case ui::ET_MOUSE_PRESSED: |
| 1069 last_mouse_event_was_move_ = false; | 1082 last_mouse_event_was_move_ = false; |
| 1070 // Make sure we're still visible before we attempt capture as the mouse | 1083 // Make sure we're still visible before we attempt capture as the mouse |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1327 | 1340 |
| 1328 //////////////////////////////////////////////////////////////////////////////// | 1341 //////////////////////////////////////////////////////////////////////////////// |
| 1329 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1342 // internal::NativeWidgetPrivate, NativeWidget implementation: |
| 1330 | 1343 |
| 1331 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1344 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
| 1332 return this; | 1345 return this; |
| 1333 } | 1346 } |
| 1334 | 1347 |
| 1335 } // namespace internal | 1348 } // namespace internal |
| 1336 } // namespace views | 1349 } // namespace views |
| OLD | NEW |