| 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/hit_test.h" | 10 #include "ui/base/hit_test.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 is_secondary_widget_(true), | 162 is_secondary_widget_(true), |
| 163 frame_type_(FRAME_TYPE_DEFAULT), | 163 frame_type_(FRAME_TYPE_DEFAULT), |
| 164 disable_inactive_rendering_(false), | 164 disable_inactive_rendering_(false), |
| 165 widget_closed_(false), | 165 widget_closed_(false), |
| 166 saved_show_state_(ui::SHOW_STATE_DEFAULT), | 166 saved_show_state_(ui::SHOW_STATE_DEFAULT), |
| 167 focus_on_creation_(true), | 167 focus_on_creation_(true), |
| 168 is_top_level_(false), | 168 is_top_level_(false), |
| 169 native_widget_initialized_(false), | 169 native_widget_initialized_(false), |
| 170 native_widget_destroyed_(false), | 170 native_widget_destroyed_(false), |
| 171 is_mouse_button_pressed_(false), | 171 is_mouse_button_pressed_(false), |
| 172 is_touch_down_(false), |
| 172 last_mouse_event_was_move_(false) { | 173 last_mouse_event_was_move_(false) { |
| 173 } | 174 } |
| 174 | 175 |
| 175 Widget::~Widget() { | 176 Widget::~Widget() { |
| 176 while (!event_stack_.empty()) { | 177 while (!event_stack_.empty()) { |
| 177 event_stack_.top()->reset(); | 178 event_stack_.top()->reset(); |
| 178 event_stack_.pop(); | 179 event_stack_.pop(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 DestroyRootView(); | 182 DestroyRootView(); |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 } | 818 } |
| 818 | 819 |
| 819 const NativeWidget* Widget::native_widget() const { | 820 const NativeWidget* Widget::native_widget() const { |
| 820 return native_widget_; | 821 return native_widget_; |
| 821 } | 822 } |
| 822 | 823 |
| 823 NativeWidget* Widget::native_widget() { | 824 NativeWidget* Widget::native_widget() { |
| 824 return native_widget_; | 825 return native_widget_; |
| 825 } | 826 } |
| 826 | 827 |
| 827 void Widget::SetMouseCapture(views::View* view) { | 828 void Widget::SetCapture(views::View* view) { |
| 828 is_mouse_button_pressed_ = true; | 829 if (internal::NativeWidgetPrivate::IsMouseButtonDown()) |
| 830 is_mouse_button_pressed_ = true; |
| 831 if (internal::NativeWidgetPrivate::IsTouchDown()) |
| 832 is_touch_down_ = true; |
| 829 root_view_->SetMouseHandler(view); | 833 root_view_->SetMouseHandler(view); |
| 830 if (!native_widget_->HasCapture()) | 834 if (!native_widget_->HasCapture()) |
| 831 native_widget_->SetCapture(); | 835 native_widget_->SetCapture(); |
| 832 } | 836 } |
| 833 | 837 |
| 834 void Widget::ReleaseMouseCapture() { | 838 void Widget::ReleaseCapture() { |
| 835 if (native_widget_->HasCapture()) | 839 if (native_widget_->HasCapture()) |
| 836 native_widget_->ReleaseCapture(); | 840 native_widget_->ReleaseCapture(); |
| 837 } | 841 } |
| 838 | 842 |
| 843 bool Widget::HasCapture() { |
| 844 return native_widget_->HasCapture(); |
| 845 } |
| 846 |
| 839 const Event* Widget::GetCurrentEvent() { | 847 const Event* Widget::GetCurrentEvent() { |
| 840 return event_stack_.empty() ? NULL : event_stack_.top()->event(); | 848 return event_stack_.empty() ? NULL : event_stack_.top()->event(); |
| 841 } | 849 } |
| 842 | 850 |
| 843 void Widget::TooltipTextChanged(View* view) { | 851 void Widget::TooltipTextChanged(View* view) { |
| 844 TooltipManager* manager = native_widget_private()->GetTooltipManager(); | 852 TooltipManager* manager = native_widget_private()->GetTooltipManager(); |
| 845 if (manager) | 853 if (manager) |
| 846 manager->TooltipTextChanged(view); | 854 manager->TooltipTextChanged(view); |
| 847 } | 855 } |
| 848 | 856 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 case ui::ET_MOUSEWHEEL: | 1088 case ui::ET_MOUSEWHEEL: |
| 1081 return GetRootView()->OnMouseWheel( | 1089 return GetRootView()->OnMouseWheel( |
| 1082 reinterpret_cast<const MouseWheelEvent&>(event)); | 1090 reinterpret_cast<const MouseWheelEvent&>(event)); |
| 1083 default: | 1091 default: |
| 1084 return false; | 1092 return false; |
| 1085 } | 1093 } |
| 1086 return true; | 1094 return true; |
| 1087 } | 1095 } |
| 1088 | 1096 |
| 1089 void Widget::OnMouseCaptureLost() { | 1097 void Widget::OnMouseCaptureLost() { |
| 1090 if (is_mouse_button_pressed_) | 1098 if (is_mouse_button_pressed_ || is_touch_down_) |
| 1091 GetRootView()->OnMouseCaptureLost(); | 1099 GetRootView()->OnMouseCaptureLost(); |
| 1100 is_touch_down_ = false; |
| 1092 is_mouse_button_pressed_ = false; | 1101 is_mouse_button_pressed_ = false; |
| 1093 } | 1102 } |
| 1094 | 1103 |
| 1095 ui::TouchStatus Widget::OnTouchEvent(const TouchEvent& event) { | 1104 ui::TouchStatus Widget::OnTouchEvent(const TouchEvent& event) { |
| 1096 ScopedEvent scoped(this, event); | 1105 ScopedEvent scoped(this, event); |
| 1097 return GetRootView()->OnTouchEvent(event); | 1106 return GetRootView()->OnTouchEvent(event); |
| 1098 } | 1107 } |
| 1099 | 1108 |
| 1100 ui::GestureStatus Widget::OnGestureEvent(const GestureEvent& event) { | 1109 ui::GestureStatus Widget::OnGestureEvent(const GestureEvent& event) { |
| 1101 ScopedEvent scoped(this, event); | 1110 ScopedEvent scoped(this, event); |
| 1111 switch (event.type()) { |
| 1112 case ui::ET_GESTURE_TAP_DOWN: |
| 1113 is_touch_down_ = true; |
| 1114 // We explicitly don't capture here. Not capturing enables multiple |
| 1115 // widgets to get tap events at the same time. Views (such as tab |
| 1116 // dragging) may explicitly capture. |
| 1117 break; |
| 1118 |
| 1119 case ui::ET_GESTURE_TAP_UP: |
| 1120 is_touch_down_ = false; |
| 1121 ReleaseCapture(); |
| 1122 break; |
| 1123 |
| 1124 default: |
| 1125 break; |
| 1126 } |
| 1102 return GetRootView()->OnGestureEvent(event); | 1127 return GetRootView()->OnGestureEvent(event); |
| 1103 } | 1128 } |
| 1104 | 1129 |
| 1105 bool Widget::ExecuteCommand(int command_id) { | 1130 bool Widget::ExecuteCommand(int command_id) { |
| 1106 return widget_delegate_->ExecuteWindowsCommand(command_id); | 1131 return widget_delegate_->ExecuteWindowsCommand(command_id); |
| 1107 } | 1132 } |
| 1108 | 1133 |
| 1109 InputMethod* Widget::GetInputMethodDirect() { | 1134 InputMethod* Widget::GetInputMethodDirect() { |
| 1110 return input_method_.get(); | 1135 return input_method_.get(); |
| 1111 } | 1136 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 | 1286 |
| 1262 //////////////////////////////////////////////////////////////////////////////// | 1287 //////////////////////////////////////////////////////////////////////////////// |
| 1263 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1288 // internal::NativeWidgetPrivate, NativeWidget implementation: |
| 1264 | 1289 |
| 1265 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1290 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
| 1266 return this; | 1291 return this; |
| 1267 } | 1292 } |
| 1268 | 1293 |
| 1269 } // namespace internal | 1294 } // namespace internal |
| 1270 } // namespace views | 1295 } // namespace views |
| OLD | NEW |