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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 disable_inactive_rendering_(false), | 166 disable_inactive_rendering_(false), |
167 widget_closed_(false), | 167 widget_closed_(false), |
168 saved_show_state_(ui::SHOW_STATE_DEFAULT), | 168 saved_show_state_(ui::SHOW_STATE_DEFAULT), |
169 focus_on_creation_(true), | 169 focus_on_creation_(true), |
170 is_top_level_(false), | 170 is_top_level_(false), |
171 native_widget_initialized_(false), | 171 native_widget_initialized_(false), |
172 native_widget_destroyed_(false), | 172 native_widget_destroyed_(false), |
173 is_mouse_button_pressed_(false), | 173 is_mouse_button_pressed_(false), |
174 is_touch_down_(false), | 174 is_touch_down_(false), |
175 last_mouse_event_was_move_(false), | 175 last_mouse_event_was_move_(false), |
| 176 auto_release_capture_(true), |
176 root_layers_dirty_(false), | 177 root_layers_dirty_(false), |
177 movement_disabled_(false) { | 178 movement_disabled_(false) { |
178 } | 179 } |
179 | 180 |
180 Widget::~Widget() { | 181 Widget::~Widget() { |
181 DestroyRootView(); | 182 DestroyRootView(); |
182 if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET) { | 183 if (ownership_ == InitParams::WIDGET_OWNS_NATIVE_WIDGET) { |
183 delete native_widget_; | 184 delete native_widget_; |
184 } else { | 185 } else { |
185 DCHECK(native_widget_destroyed_) | 186 DCHECK(native_widget_destroyed_) |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1153 if (!native_widget_->HasCapture()) | 1154 if (!native_widget_->HasCapture()) |
1154 native_widget_->SetCapture(); | 1155 native_widget_->SetCapture(); |
1155 event->SetHandled(); | 1156 event->SetHandled(); |
1156 } | 1157 } |
1157 return; | 1158 return; |
1158 } | 1159 } |
1159 case ui::ET_MOUSE_RELEASED: | 1160 case ui::ET_MOUSE_RELEASED: |
1160 last_mouse_event_was_move_ = false; | 1161 last_mouse_event_was_move_ = false; |
1161 is_mouse_button_pressed_ = false; | 1162 is_mouse_button_pressed_ = false; |
1162 // Release capture first, to avoid confusion if OnMouseReleased blocks. | 1163 // Release capture first, to avoid confusion if OnMouseReleased blocks. |
1163 if (native_widget_->HasCapture() && | 1164 if (auto_release_capture_ && native_widget_->HasCapture()) |
1164 ShouldReleaseCaptureOnMouseReleased()) { | |
1165 native_widget_->ReleaseCapture(); | 1165 native_widget_->ReleaseCapture(); |
1166 } | |
1167 if (root_view) | 1166 if (root_view) |
1168 root_view->OnMouseReleased(*event); | 1167 root_view->OnMouseReleased(*event); |
1169 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0) | 1168 if ((event->flags() & ui::EF_IS_NON_CLIENT) == 0) |
1170 event->SetHandled(); | 1169 event->SetHandled(); |
1171 return; | 1170 return; |
1172 case ui::ET_MOUSE_MOVED: | 1171 case ui::ET_MOUSE_MOVED: |
1173 case ui::ET_MOUSE_DRAGGED: | 1172 case ui::ET_MOUSE_DRAGGED: |
1174 if (native_widget_->HasCapture() && is_mouse_button_pressed_) { | 1173 if (native_widget_->HasCapture() && is_mouse_button_pressed_) { |
1175 last_mouse_event_was_move_ = false; | 1174 last_mouse_event_was_move_ = false; |
1176 if (root_view) | 1175 if (root_view) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 case ui::ET_GESTURE_TAP_DOWN: | 1223 case ui::ET_GESTURE_TAP_DOWN: |
1225 is_touch_down_ = true; | 1224 is_touch_down_ = true; |
1226 // We explicitly don't capture here. Not capturing enables multiple | 1225 // We explicitly don't capture here. Not capturing enables multiple |
1227 // widgets to get tap events at the same time. Views (such as tab | 1226 // widgets to get tap events at the same time. Views (such as tab |
1228 // dragging) may explicitly capture. | 1227 // dragging) may explicitly capture. |
1229 break; | 1228 break; |
1230 | 1229 |
1231 case ui::ET_GESTURE_END: | 1230 case ui::ET_GESTURE_END: |
1232 if (event->details().touch_points() == 1) { | 1231 if (event->details().touch_points() == 1) { |
1233 is_touch_down_ = false; | 1232 is_touch_down_ = false; |
1234 if (ShouldReleaseCaptureOnMouseReleased()) | 1233 if (auto_release_capture_) |
1235 ReleaseCapture(); | 1234 ReleaseCapture(); |
1236 } | 1235 } |
1237 break; | 1236 break; |
1238 | 1237 |
1239 default: | 1238 default: |
1240 break; | 1239 break; |
1241 } | 1240 } |
1242 static_cast<internal::RootView*>(GetRootView())->DispatchGestureEvent(event); | 1241 static_cast<internal::RootView*>(GetRootView())->DispatchGestureEvent(event); |
1243 } | 1242 } |
1244 | 1243 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 void Widget::DestroyRootView() { | 1306 void Widget::DestroyRootView() { |
1308 non_client_view_ = NULL; | 1307 non_client_view_ = NULL; |
1309 root_view_.reset(); | 1308 root_view_.reset(); |
1310 // Input method has to be destroyed before focus manager. | 1309 // Input method has to be destroyed before focus manager. |
1311 input_method_.reset(); | 1310 input_method_.reset(); |
1312 } | 1311 } |
1313 | 1312 |
1314 //////////////////////////////////////////////////////////////////////////////// | 1313 //////////////////////////////////////////////////////////////////////////////// |
1315 // Widget, private: | 1314 // Widget, private: |
1316 | 1315 |
1317 bool Widget::ShouldReleaseCaptureOnMouseReleased() const { | |
1318 return true; | |
1319 } | |
1320 | |
1321 void Widget::SetInactiveRenderingDisabled(bool value) { | 1316 void Widget::SetInactiveRenderingDisabled(bool value) { |
1322 if (value == disable_inactive_rendering_) | 1317 if (value == disable_inactive_rendering_) |
1323 return; | 1318 return; |
1324 | 1319 |
1325 disable_inactive_rendering_ = value; | 1320 disable_inactive_rendering_ = value; |
1326 if (non_client_view_) | 1321 if (non_client_view_) |
1327 non_client_view_->SetInactiveRenderingDisabled(value); | 1322 non_client_view_->SetInactiveRenderingDisabled(value); |
1328 native_widget_->SetInactiveRenderingDisabled(value); | 1323 native_widget_->SetInactiveRenderingDisabled(value); |
1329 } | 1324 } |
1330 | 1325 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1427 | 1422 |
1428 //////////////////////////////////////////////////////////////////////////////// | 1423 //////////////////////////////////////////////////////////////////////////////// |
1429 // internal::NativeWidgetPrivate, NativeWidget implementation: | 1424 // internal::NativeWidgetPrivate, NativeWidget implementation: |
1430 | 1425 |
1431 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { | 1426 internal::NativeWidgetPrivate* NativeWidgetPrivate::AsNativeWidgetPrivate() { |
1432 return this; | 1427 return this; |
1433 } | 1428 } |
1434 | 1429 |
1435 } // namespace internal | 1430 } // namespace internal |
1436 } // namespace views | 1431 } // namespace views |
OLD | NEW |