OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/root_view.h" | 5 #include "views/widget/root_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/drag_drop_types.h" | 9 #include "app/drag_drop_types.h" |
10 #include "app/keyboard_codes.h" | 10 #include "app/keyboard_codes.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "gfx/canvas_skia.h" | 13 #include "gfx/canvas_skia.h" |
14 #include "views/fill_layout.h" | 14 #include "views/fill_layout.h" |
15 #include "views/focus/view_storage.h" | 15 #include "views/focus/view_storage.h" |
16 #include "views/widget/widget.h" | 16 #include "views/widget/widget.h" |
17 #include "views/window/window.h" | 17 #include "views/window/window.h" |
18 | 18 |
| 19 #if defined(TOUCH_UI) |
| 20 #include "views/touchui/gesture_manager.h" |
| 21 #endif |
| 22 |
19 #if defined(OS_LINUX) | 23 #if defined(OS_LINUX) |
20 #include "views/widget/widget_gtk.h" | 24 #include "views/widget/widget_gtk.h" |
21 #endif // defined(OS_LINUX) | 25 #endif // defined(OS_LINUX) |
22 | 26 |
23 namespace views { | 27 namespace views { |
24 | 28 |
25 ///////////////////////////////////////////////////////////////////////////// | 29 ///////////////////////////////////////////////////////////////////////////// |
26 // | 30 // |
27 // A Task to trigger non urgent painting. | 31 // A Task to trigger non urgent painting. |
28 // | 32 // |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 explicit_mouse_handler_(false), | 73 explicit_mouse_handler_(false), |
70 #if defined(OS_WIN) | 74 #if defined(OS_WIN) |
71 previous_cursor_(NULL), | 75 previous_cursor_(NULL), |
72 #endif | 76 #endif |
73 default_keyboard_handler_(NULL), | 77 default_keyboard_handler_(NULL), |
74 focus_on_mouse_pressed_(false), | 78 focus_on_mouse_pressed_(false), |
75 ignore_set_focus_calls_(false), | 79 ignore_set_focus_calls_(false), |
76 focus_traversable_parent_(NULL), | 80 focus_traversable_parent_(NULL), |
77 focus_traversable_parent_view_(NULL), | 81 focus_traversable_parent_view_(NULL), |
78 drag_view_(NULL) | 82 drag_view_(NULL) |
| 83 #if defined(TOUCH_UI) |
| 84 , |
| 85 gesture_manager_(GestureManager::Get()), |
| 86 touch_pressed_handler_(NULL) |
| 87 #endif |
79 #ifndef NDEBUG | 88 #ifndef NDEBUG |
80 , | 89 , |
81 is_processing_paint_(false) | 90 is_processing_paint_(false) |
82 #endif | 91 #endif |
83 { | 92 { |
84 } | 93 } |
85 | 94 |
86 RootView::~RootView() { | 95 RootView::~RootView() { |
87 // If we have children remove them explicitly so to make sure a remove | 96 // If we have children remove them explicitly so to make sure a remove |
88 // notification is sent for each one of them. | 97 // notification is sent for each one of them. |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 focus_manager->ViewRemoved(parent, child); | 291 focus_manager->ViewRemoved(parent, child); |
283 | 292 |
284 ViewStorage::GetSharedInstance()->ViewRemoved(parent, child); | 293 ViewStorage::GetSharedInstance()->ViewRemoved(parent, child); |
285 } | 294 } |
286 } | 295 } |
287 | 296 |
288 void RootView::SetFocusOnMousePressed(bool f) { | 297 void RootView::SetFocusOnMousePressed(bool f) { |
289 focus_on_mouse_pressed_ = f; | 298 focus_on_mouse_pressed_ = f; |
290 } | 299 } |
291 | 300 |
| 301 #if defined(TOUCH_UI) |
| 302 bool RootView::OnTouchEvent(const TouchEvent& e) { |
| 303 // If touch_pressed_handler_ is non null, we are currently processing |
| 304 // a touch down on the screen situation. In that case we send the |
| 305 // event to touch_pressed_handler_ |
| 306 |
| 307 if (touch_pressed_handler_) { |
| 308 TouchEvent touch_event(e, this, touch_pressed_handler_); |
| 309 touch_pressed_handler_->ProcessTouchEvent(touch_event); |
| 310 gesture_manager_->ProcessTouchEventForGesture(e, this, true); |
| 311 return true; |
| 312 } |
| 313 |
| 314 bool handled = false; |
| 315 // Walk up the tree until we find a view that wants the touch event. |
| 316 for (touch_pressed_handler_ = GetViewForPoint(e.location()); |
| 317 touch_pressed_handler_ && (touch_pressed_handler_ != this); |
| 318 touch_pressed_handler_ = touch_pressed_handler_->GetParent()) { |
| 319 if (!touch_pressed_handler_->IsEnabled()) { |
| 320 // Disabled views eat events but are treated as not handled by the |
| 321 // the GestureManager. |
| 322 handled = false; |
| 323 break; |
| 324 } |
| 325 |
| 326 // See if this view wants to handle the touch |
| 327 TouchEvent touch_event(e, this, touch_pressed_handler_); |
| 328 handled = touch_pressed_handler_->ProcessTouchEvent(touch_event); |
| 329 |
| 330 // The view could have removed itself from the tree when handling |
| 331 // OnTouchEvent(). So handle as per OnMousePressed. NB: we |
| 332 // assume that the RootView itself cannot be so removed. |
| 333 // |
| 334 // NOTE: Don't return true here, because we don't want the frame to |
| 335 // forward future events to us when there's no handler. |
| 336 if (!touch_pressed_handler_) |
| 337 break; |
| 338 |
| 339 // If the view handled the event, leave touch_pressed_handler_ set and |
| 340 // return true, which will cause subsequent drag/release events to get |
| 341 // forwarded to that view. |
| 342 if (handled) { |
| 343 gesture_manager_->ProcessTouchEventForGesture(e, this, handled); |
| 344 return true; |
| 345 } |
| 346 } |
| 347 |
| 348 // Reset touch_pressed_handler_ to indicate that no processing is occurring. |
| 349 touch_pressed_handler_ = NULL; |
| 350 |
| 351 // Give the touch event to the gesture manager. |
| 352 gesture_manager_->ProcessTouchEventForGesture(e, this, handled); |
| 353 return handled; |
| 354 } |
| 355 #endif |
| 356 |
292 bool RootView::OnMousePressed(const MouseEvent& e) { | 357 bool RootView::OnMousePressed(const MouseEvent& e) { |
293 // This function does not normally handle non-client messages except for | 358 // This function does not normally handle non-client messages except for |
294 // non-client double-clicks. Actually, all double-clicks are special as the | 359 // non-client double-clicks. Actually, all double-clicks are special as the |
295 // are formed from a single-click followed by a double-click event. When the | 360 // are formed from a single-click followed by a double-click event. When the |
296 // double-click event lands on a different view than its single-click part, | 361 // double-click event lands on a different view than its single-click part, |
297 // we transform it into a single-click which prevents odd things. | 362 // we transform it into a single-click which prevents odd things. |
298 if ((e.GetFlags() & MouseEvent::EF_IS_NON_CLIENT) && | 363 if ((e.GetFlags() & MouseEvent::EF_IS_NON_CLIENT) && |
299 !(e.GetFlags() & MouseEvent::EF_IS_DOUBLE_CLICK)) { | 364 !(e.GetFlags() & MouseEvent::EF_IS_DOUBLE_CLICK)) { |
300 last_click_handler_ = NULL; | 365 last_click_handler_ = NULL; |
301 return false; | 366 return false; |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 static_cast<WidgetGtk*>(GetWidget())->window_contents(); | 775 static_cast<WidgetGtk*>(GetWidget())->window_contents(); |
711 if (!native_view) | 776 if (!native_view) |
712 return; | 777 return; |
713 gdk_window_set_cursor(native_view->window, cursor); | 778 gdk_window_set_cursor(native_view->window, cursor); |
714 if (cursor) | 779 if (cursor) |
715 gdk_cursor_destroy(cursor); | 780 gdk_cursor_destroy(cursor); |
716 #endif | 781 #endif |
717 } | 782 } |
718 | 783 |
719 } // namespace views | 784 } // namespace views |
OLD | NEW |