| 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/root_view.h" | 5 #include "views/widget/root_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #if defined(TOUCH_UI) && defined(HAVE_XINPUT2) | 9 #if defined(TOUCH_UI) && defined(HAVE_XINPUT2) |
| 10 #include <gdk/gdkx.h> | 10 #include <gdk/gdkx.h> |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 last_mouse_event_x_(-1), | 112 last_mouse_event_x_(-1), |
| 113 last_mouse_event_y_(-1), | 113 last_mouse_event_y_(-1), |
| 114 #if defined(TOUCH_UI) | 114 #if defined(TOUCH_UI) |
| 115 gesture_manager_(GestureManager::GetInstance()), | 115 gesture_manager_(GestureManager::GetInstance()), |
| 116 touch_pressed_handler_(NULL), | 116 touch_pressed_handler_(NULL), |
| 117 #endif | 117 #endif |
| 118 ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)), | 118 ALLOW_THIS_IN_INITIALIZER_LIST(focus_search_(this, false, false)), |
| 119 focus_on_mouse_pressed_(false), | 119 focus_on_mouse_pressed_(false), |
| 120 ignore_set_focus_calls_(false), | 120 ignore_set_focus_calls_(false), |
| 121 focus_traversable_parent_(NULL), | 121 focus_traversable_parent_(NULL), |
| 122 focus_traversable_parent_view_(NULL), | 122 focus_traversable_parent_view_(NULL) { |
| 123 drag_view_(NULL) { | |
| 124 } | 123 } |
| 125 | 124 |
| 126 RootView::~RootView() { | 125 RootView::~RootView() { |
| 127 // If we have children remove them explicitly so to make sure a remove | 126 // If we have children remove them explicitly so to make sure a remove |
| 128 // notification is sent for each one of them. | 127 // notification is sent for each one of them. |
| 129 if (has_children()) | 128 if (has_children()) |
| 130 RemoveAllChildViews(true); | 129 RemoveAllChildViews(true); |
| 131 | 130 |
| 132 if (pending_paint_task_) | 131 if (pending_paint_task_) |
| 133 pending_paint_task_->Cancel(); // Ensure we're not called any more. | 132 pending_paint_task_->Cancel(); // Ensure we're not called any more. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (mouse_move_handler_ != NULL) { | 206 if (mouse_move_handler_ != NULL) { |
| 208 MouseEvent exited_event(ui::ET_MOUSE_EXITED, 0, 0, 0); | 207 MouseEvent exited_event(ui::ET_MOUSE_EXITED, 0, 0, 0); |
| 209 mouse_move_handler_->OnMouseExited(exited_event); | 208 mouse_move_handler_->OnMouseExited(exited_event); |
| 210 mouse_move_handler_ = NULL; | 209 mouse_move_handler_ = NULL; |
| 211 } | 210 } |
| 212 } | 211 } |
| 213 | 212 |
| 214 bool RootView::ProcessKeyEvent(const KeyEvent& event) { | 213 bool RootView::ProcessKeyEvent(const KeyEvent& event) { |
| 215 bool consumed = false; | 214 bool consumed = false; |
| 216 | 215 |
| 217 View* v = GetFocusedView(); | 216 View* v = GetFocusManager()->GetFocusedView(); |
| 218 // Special case to handle right-click context menus triggered by the | 217 // Special case to handle right-click context menus triggered by the |
| 219 // keyboard. | 218 // keyboard. |
| 220 if (v && v->IsEnabled() && ((event.key_code() == ui::VKEY_APPS) || | 219 if (v && v->IsEnabled() && ((event.key_code() == ui::VKEY_APPS) || |
| 221 (event.key_code() == ui::VKEY_F10 && event.IsShiftDown()))) { | 220 (event.key_code() == ui::VKEY_F10 && event.IsShiftDown()))) { |
| 222 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); | 221 v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); |
| 223 return true; | 222 return true; |
| 224 } | 223 } |
| 225 for (; v && v != this && !consumed; v = v->parent()) { | 224 for (; v && v != this && !consumed; v = v->parent()) { |
| 226 consumed = (event.type() == ui::ET_KEY_PRESSED) ? | 225 consumed = (event.type() == ui::ET_KEY_PRESSED) ? |
| 227 v->OnKeyPressed(event) : v->OnKeyReleased(event); | 226 v->OnKeyPressed(event) : v->OnKeyReleased(event); |
| 228 } | 227 } |
| 229 | 228 |
| 230 if (!consumed && default_keyboard_handler_) { | 229 if (!consumed && default_keyboard_handler_) { |
| 231 consumed = (event.type() == ui::ET_KEY_PRESSED) ? | 230 consumed = (event.type() == ui::ET_KEY_PRESSED) ? |
| 232 default_keyboard_handler_->OnKeyPressed(event) : | 231 default_keyboard_handler_->OnKeyPressed(event) : |
| 233 default_keyboard_handler_->OnKeyReleased(event); | 232 default_keyboard_handler_->OnKeyReleased(event); |
| 234 } | 233 } |
| 235 | 234 |
| 236 return consumed; | 235 return consumed; |
| 237 } | 236 } |
| 238 | 237 |
| 239 void RootView::SetDefaultKeyboardHandler(View* v) { | 238 void RootView::SetDefaultKeyboardHandler(View* v) { |
| 240 default_keyboard_handler_ = v; | 239 default_keyboard_handler_ = v; |
| 241 } | 240 } |
| 242 | 241 |
| 243 bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) { | 242 bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) { |
| 244 View* v; | 243 View* v; |
| 245 bool consumed = false; | 244 bool consumed = false; |
| 246 if (GetFocusedView()) { | 245 View* focused_view = GetFocusManager()->GetFocusedView(); |
| 247 for (v = GetFocusedView(); v && v != this && !consumed; v = v->parent()) | 246 if (focused_view) { |
| 247 for (v = focused_view; v && v != this && !consumed; v = v->parent()) |
| 248 consumed = v->OnMouseWheel(e); | 248 consumed = v->OnMouseWheel(e); |
| 249 } | 249 } |
| 250 | 250 |
| 251 if (!consumed && default_keyboard_handler_) { | 251 if (!consumed && default_keyboard_handler_) { |
| 252 consumed = default_keyboard_handler_->OnMouseWheel(e); | 252 consumed = default_keyboard_handler_->OnMouseWheel(e); |
| 253 } | 253 } |
| 254 return consumed; | 254 return consumed; |
| 255 } | 255 } |
| 256 | 256 |
| 257 // Focus ----------------------------------------------------------------------- | 257 // Focus ----------------------------------------------------------------------- |
| 258 | 258 |
| 259 void RootView::FocusView(View* view) { | |
| 260 if (view != GetFocusedView()) { | |
| 261 FocusManager* focus_manager = GetFocusManager(); | |
| 262 // TODO(jcampan): This fails under WidgetGtk with TYPE_CHILD. | |
| 263 // (see http://crbug.com/21335) Reenable DCHECK and | |
| 264 // verify GetFocusManager works as expecte. | |
| 265 #if defined(OS_WIN) | |
| 266 DCHECK(focus_manager) << "No Focus Manager for Window " << | |
| 267 (GetWidget() ? GetWidget()->GetNativeView() : 0); | |
| 268 #endif | |
| 269 if (!focus_manager) | |
| 270 return; | |
| 271 focus_manager->SetFocusedView(view); | |
| 272 } | |
| 273 } | |
| 274 | |
| 275 View* RootView::GetFocusedView() { | |
| 276 FocusManager* focus_manager = GetFocusManager(); | |
| 277 if (!focus_manager) { | |
| 278 // We may not have a FocusManager when the window that contains us is being | |
| 279 // deleted. Sadly we cannot wait for the window to be destroyed before we | |
| 280 // remove the FocusManager (see xp_frame.cc for more info). | |
| 281 return NULL; | |
| 282 } | |
| 283 | |
| 284 // Make sure the focused view belongs to this RootView's view hierarchy. | |
| 285 View* view = focus_manager->GetFocusedView(); | |
| 286 if (view && (view->GetRootView() == this)) | |
| 287 return view; | |
| 288 | |
| 289 #if defined(OS_LINUX) | |
| 290 if (view && NativeTextfieldViews::IsTextfieldViewsEnabled()) { | |
| 291 // hack to deal with two root views. | |
| 292 // should be fixed by eliminating one of them | |
| 293 return view; | |
| 294 } | |
| 295 #endif | |
| 296 return NULL; | |
| 297 } | |
| 298 | |
| 299 void RootView::SetFocusOnMousePressed(bool f) { | 259 void RootView::SetFocusOnMousePressed(bool f) { |
| 300 focus_on_mouse_pressed_ = f; | 260 focus_on_mouse_pressed_ = f; |
| 301 } | 261 } |
| 302 | 262 |
| 303 void RootView::SetFocusTraversableParent(FocusTraversable* focus_traversable) { | 263 void RootView::SetFocusTraversableParent(FocusTraversable* focus_traversable) { |
| 304 DCHECK(focus_traversable != this); | 264 DCHECK(focus_traversable != this); |
| 305 focus_traversable_parent_ = focus_traversable; | 265 focus_traversable_parent_ = focus_traversable; |
| 306 } | 266 } |
| 307 | 267 |
| 308 void RootView::SetFocusTraversableParentView(View* view) { | 268 void RootView::SetFocusTraversableParentView(View* view) { |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 | 614 |
| 655 std::string RootView::GetClassName() const { | 615 std::string RootView::GetClassName() const { |
| 656 return kViewClassName; | 616 return kViewClassName; |
| 657 } | 617 } |
| 658 | 618 |
| 659 AccessibilityTypes::Role RootView::GetAccessibleRole() { | 619 AccessibilityTypes::Role RootView::GetAccessibleRole() { |
| 660 return AccessibilityTypes::ROLE_APPLICATION; | 620 return AccessibilityTypes::ROLE_APPLICATION; |
| 661 } | 621 } |
| 662 | 622 |
| 663 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { | 623 void RootView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { |
| 624 widget_->ViewHierarchyChanged(is_add, parent, child); |
| 625 |
| 664 if (!is_add) { | 626 if (!is_add) { |
| 665 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child) { | 627 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == child) |
| 666 mouse_pressed_handler_ = NULL; | 628 mouse_pressed_handler_ = NULL; |
| 667 } | 629 if (mouse_move_handler_ == child) |
| 668 | |
| 669 if (widget_) | |
| 670 widget_->ViewHierarchyChanged(is_add, parent, child); | |
| 671 | |
| 672 if (mouse_move_handler_ == child) { | |
| 673 mouse_move_handler_ = NULL; | 630 mouse_move_handler_ = NULL; |
| 674 } | 631 if (default_keyboard_handler_ == child) |
| 675 | |
| 676 if (GetFocusedView() == child) { | |
| 677 FocusView(NULL); | |
| 678 } | |
| 679 | |
| 680 if (child == drag_view_) | |
| 681 drag_view_ = NULL; | |
| 682 | |
| 683 if (default_keyboard_handler_ == child) { | |
| 684 default_keyboard_handler_ = NULL; | 632 default_keyboard_handler_ = NULL; |
| 685 } | |
| 686 | |
| 687 #if defined(TOUCH_UI) | 633 #if defined(TOUCH_UI) |
| 688 if (touch_pressed_handler_) { | 634 if (touch_pressed_handler_) |
| 689 touch_pressed_handler_ = NULL; | 635 touch_pressed_handler_ = NULL; |
| 690 } | |
| 691 #endif | 636 #endif |
| 692 | |
| 693 FocusManager* focus_manager = widget_->GetFocusManager(); | |
| 694 // An unparanted RootView does not have a FocusManager. | |
| 695 if (focus_manager) | |
| 696 focus_manager->ViewRemoved(parent, child); | |
| 697 | |
| 698 ViewStorage::GetInstance()->ViewRemoved(parent, child); | |
| 699 } | 637 } |
| 700 } | 638 } |
| 701 | 639 |
| 702 //////////////////////////////////////////////////////////////////////////////// | 640 //////////////////////////////////////////////////////////////////////////////// |
| 703 // RootView, protected: | 641 // RootView, protected: |
| 704 | 642 |
| 705 // Coordinate conversion ------------------------------------------------------- | 643 // Coordinate conversion ------------------------------------------------------- |
| 706 | 644 |
| 707 bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, | 645 bool RootView::ConvertPointToMouseHandler(const gfx::Point& l, |
| 708 gfx::Point* p) { | 646 gfx::Point* p) { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 gdk_window_set_cursor(native_view->window, cursor); | 704 gdk_window_set_cursor(native_view->window, cursor); |
| 767 #endif | 705 #endif |
| 768 } | 706 } |
| 769 | 707 |
| 770 void RootView::SetMouseLocationAndFlags(const MouseEvent& e) { | 708 void RootView::SetMouseLocationAndFlags(const MouseEvent& e) { |
| 771 last_mouse_event_flags_ = e.flags(); | 709 last_mouse_event_flags_ = e.flags(); |
| 772 last_mouse_event_x_ = e.x(); | 710 last_mouse_event_x_ = e.x(); |
| 773 last_mouse_event_y_ = e.y(); | 711 last_mouse_event_y_ = e.y(); |
| 774 } | 712 } |
| 775 | 713 |
| 776 // Drag and drop --------------------------------------------------------------- | |
| 777 | |
| 778 View* RootView::GetDragView() { | |
| 779 return drag_view_; | |
| 780 } | |
| 781 | |
| 782 } // namespace views | 714 } // namespace views |
| OLD | NEW |