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 "ui/views/view.h" | 5 #include "ui/views/view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 return IsVisible() && parent_ ? parent_->IsVisibleInRootView() : false; | 406 return IsVisible() && parent_ ? parent_->IsVisibleInRootView() : false; |
407 } | 407 } |
408 | 408 |
409 void View::SetEnabled(bool enabled) { | 409 void View::SetEnabled(bool enabled) { |
410 if (enabled != enabled_) { | 410 if (enabled != enabled_) { |
411 enabled_ = enabled; | 411 enabled_ = enabled; |
412 OnEnabledChanged(); | 412 OnEnabledChanged(); |
413 } | 413 } |
414 } | 414 } |
415 | 415 |
416 bool View::IsEnabled() const { | |
417 return enabled_; | |
418 } | |
419 | |
420 void View::OnEnabledChanged() { | 416 void View::OnEnabledChanged() { |
421 SchedulePaint(); | 417 SchedulePaint(); |
422 } | 418 } |
423 | 419 |
424 // Transformations ------------------------------------------------------------- | 420 // Transformations ------------------------------------------------------------- |
425 | 421 |
426 const ui::Transform& View::GetTransform() const { | 422 const ui::Transform& View::GetTransform() const { |
427 static const ui::Transform* no_op = new ui::Transform; | 423 static const ui::Transform* no_op = new ui::Transform; |
428 return layer() ? layer()->transform() : *no_op; | 424 return layer() ? layer()->transform() : *no_op; |
429 } | 425 } |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 void View::SetNextFocusableView(View* view) { | 896 void View::SetNextFocusableView(View* view) { |
901 view->previous_focusable_view_ = this; | 897 view->previous_focusable_view_ = this; |
902 next_focusable_view_ = view; | 898 next_focusable_view_ = view; |
903 } | 899 } |
904 | 900 |
905 bool View::IsFocusableInRootView() const { | 901 bool View::IsFocusableInRootView() const { |
906 return IsFocusable() && IsVisibleInRootView(); | 902 return IsFocusable() && IsVisibleInRootView(); |
907 } | 903 } |
908 | 904 |
909 bool View::IsAccessibilityFocusableInRootView() const { | 905 bool View::IsAccessibilityFocusableInRootView() const { |
910 return (focusable_ || accessibility_focusable_) && IsEnabled() && | 906 return (focusable_ || accessibility_focusable_) && enabled_ && |
911 IsVisibleInRootView(); | 907 IsVisibleInRootView(); |
912 } | 908 } |
913 | 909 |
914 FocusManager* View::GetFocusManager() { | 910 FocusManager* View::GetFocusManager() { |
915 Widget* widget = GetWidget(); | 911 Widget* widget = GetWidget(); |
916 return widget ? widget->GetFocusManager() : NULL; | 912 return widget ? widget->GetFocusManager() : NULL; |
917 } | 913 } |
918 | 914 |
919 const FocusManager* View::GetFocusManager() const { | 915 const FocusManager* View::GetFocusManager() const { |
920 const Widget* widget = GetWidget(); | 916 const Widget* widget = GetWidget(); |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1232 return false; | 1228 return false; |
1233 } | 1229 } |
1234 | 1230 |
1235 void View::GetHitTestMask(gfx::Path* mask) const { | 1231 void View::GetHitTestMask(gfx::Path* mask) const { |
1236 DCHECK(mask); | 1232 DCHECK(mask); |
1237 } | 1233 } |
1238 | 1234 |
1239 // Focus ----------------------------------------------------------------------- | 1235 // Focus ----------------------------------------------------------------------- |
1240 | 1236 |
1241 bool View::IsFocusable() const { | 1237 bool View::IsFocusable() const { |
1242 return focusable_ && IsEnabled() && IsVisible(); | 1238 return focusable_ && enabled_ && IsVisible(); |
1243 } | 1239 } |
1244 | 1240 |
1245 void View::OnFocus() { | 1241 void View::OnFocus() { |
1246 // TODO(beng): Investigate whether it's possible for us to move this to | 1242 // TODO(beng): Investigate whether it's possible for us to move this to |
1247 // Focus(). | 1243 // Focus(). |
1248 // By default, we clear the native focus. This ensures that no visible native | 1244 // By default, we clear the native focus. This ensures that no visible native |
1249 // view as the focus and that we still receive keyboard inputs. | 1245 // view as the focus and that we still receive keyboard inputs. |
1250 FocusManager* focus_manager = GetFocusManager(); | 1246 FocusManager* focus_manager = GetFocusManager(); |
1251 if (focus_manager) | 1247 if (focus_manager) |
1252 focus_manager->ClearNativeFocus(); | 1248 focus_manager->ClearNativeFocus(); |
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1844 gfx::Point offset; | 1840 gfx::Point offset; |
1845 CalculateOffsetToAncestorWithLayer(&offset, NULL); | 1841 CalculateOffsetToAncestorWithLayer(&offset, NULL); |
1846 UpdateChildLayerBounds(offset); | 1842 UpdateChildLayerBounds(offset); |
1847 | 1843 |
1848 SchedulePaint(); | 1844 SchedulePaint(); |
1849 } | 1845 } |
1850 | 1846 |
1851 // Input ----------------------------------------------------------------------- | 1847 // Input ----------------------------------------------------------------------- |
1852 | 1848 |
1853 bool View::ProcessMousePressed(const MouseEvent& event, DragInfo* drag_info) { | 1849 bool View::ProcessMousePressed(const MouseEvent& event, DragInfo* drag_info) { |
1854 const bool enabled = IsEnabled(); | |
1855 int drag_operations = | 1850 int drag_operations = |
1856 (enabled && event.IsOnlyLeftMouseButton() && HitTest(event.location())) ? | 1851 (enabled_ && event.IsOnlyLeftMouseButton() && HitTest(event.location())) ? |
1857 GetDragOperations(event.location()) : 0; | 1852 GetDragOperations(event.location()) : 0; |
1858 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? | 1853 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? |
1859 context_menu_controller_ : 0; | 1854 context_menu_controller_ : 0; |
1860 | 1855 |
1861 const bool result = OnMousePressed(event); | 1856 const bool result = OnMousePressed(event); |
1862 // WARNING: we may have been deleted, don't use any View variables. | 1857 // WARNING: we may have been deleted, don't use any View variables. |
1863 | 1858 |
1864 if (!enabled) | 1859 if (!enabled_) |
1865 return result; | 1860 return result; |
1866 | 1861 |
1867 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { | 1862 if (drag_operations != ui::DragDropTypes::DRAG_NONE) { |
1868 drag_info->PossibleDrag(event.location()); | 1863 drag_info->PossibleDrag(event.location()); |
1869 return true; | 1864 return true; |
1870 } | 1865 } |
1871 return !!context_menu_controller || result; | 1866 return !!context_menu_controller || result; |
1872 } | 1867 } |
1873 | 1868 |
1874 bool View::ProcessMouseDragged(const MouseEvent& event, DragInfo* drag_info) { | 1869 bool View::ProcessMouseDragged(const MouseEvent& event, DragInfo* drag_info) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2052 | 2047 |
2053 OSExchangeData data; | 2048 OSExchangeData data; |
2054 WriteDragData(press_pt, &data); | 2049 WriteDragData(press_pt, &data); |
2055 | 2050 |
2056 // Message the RootView to do the drag and drop. That way if we're removed | 2051 // Message the RootView to do the drag and drop. That way if we're removed |
2057 // the RootView can detect it and avoid calling us back. | 2052 // the RootView can detect it and avoid calling us back. |
2058 GetWidget()->RunShellDrag(this, data, drag_operations); | 2053 GetWidget()->RunShellDrag(this, data, drag_operations); |
2059 } | 2054 } |
2060 | 2055 |
2061 } // namespace views | 2056 } // namespace views |
OLD | NEW |