| 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/view.h" | 5 #include "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 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 return NULL; | 797 return NULL; |
| 798 } | 798 } |
| 799 | 799 |
| 800 InputMethod* View::GetInputMethod() { | 800 InputMethod* View::GetInputMethod() { |
| 801 Widget* widget = GetWidget(); | 801 Widget* widget = GetWidget(); |
| 802 return widget ? widget->GetInputMethod() : NULL; | 802 return widget ? widget->GetInputMethod() : NULL; |
| 803 } | 803 } |
| 804 | 804 |
| 805 // Accelerators ---------------------------------------------------------------- | 805 // Accelerators ---------------------------------------------------------------- |
| 806 | 806 |
| 807 void View::AddAccelerator(const Accelerator& accelerator) { | 807 void View::AddAccelerator(const ui::Accelerator& accelerator) { |
| 808 if (!accelerators_.get()) | 808 if (!accelerators_.get()) |
| 809 accelerators_.reset(new std::vector<Accelerator>()); | 809 accelerators_.reset(new std::vector<ui::Accelerator>()); |
| 810 | 810 |
| 811 DCHECK(std::find(accelerators_->begin(), accelerators_->end(), accelerator) == | 811 DCHECK(std::find(accelerators_->begin(), accelerators_->end(), accelerator) == |
| 812 accelerators_->end()) | 812 accelerators_->end()) |
| 813 << "Registering the same accelerator multiple times"; | 813 << "Registering the same accelerator multiple times"; |
| 814 | 814 |
| 815 accelerators_->push_back(accelerator); | 815 accelerators_->push_back(accelerator); |
| 816 RegisterPendingAccelerators(); | 816 RegisterPendingAccelerators(); |
| 817 } | 817 } |
| 818 | 818 |
| 819 void View::RemoveAccelerator(const Accelerator& accelerator) { | 819 void View::RemoveAccelerator(const ui::Accelerator& accelerator) { |
| 820 if (!accelerators_.get()) { | 820 if (!accelerators_.get()) { |
| 821 NOTREACHED() << "Removing non-existing accelerator"; | 821 NOTREACHED() << "Removing non-existing accelerator"; |
| 822 return; | 822 return; |
| 823 } | 823 } |
| 824 | 824 |
| 825 std::vector<Accelerator>::iterator i( | 825 std::vector<ui::Accelerator>::iterator i( |
| 826 std::find(accelerators_->begin(), accelerators_->end(), accelerator)); | 826 std::find(accelerators_->begin(), accelerators_->end(), accelerator)); |
| 827 if (i == accelerators_->end()) { | 827 if (i == accelerators_->end()) { |
| 828 NOTREACHED() << "Removing non-existing accelerator"; | 828 NOTREACHED() << "Removing non-existing accelerator"; |
| 829 return; | 829 return; |
| 830 } | 830 } |
| 831 | 831 |
| 832 size_t index = i - accelerators_->begin(); | 832 size_t index = i - accelerators_->begin(); |
| 833 accelerators_->erase(i); | 833 accelerators_->erase(i); |
| 834 if (index >= registered_accelerator_count_) { | 834 if (index >= registered_accelerator_count_) { |
| 835 // The accelerator is not registered to FocusManager. | 835 // The accelerator is not registered to FocusManager. |
| 836 return; | 836 return; |
| 837 } | 837 } |
| 838 --registered_accelerator_count_; | 838 --registered_accelerator_count_; |
| 839 | 839 |
| 840 // Providing we are attached to a Widget and registered with a focus manager, | 840 // Providing we are attached to a Widget and registered with a focus manager, |
| 841 // we should de-register from that focus manager now. | 841 // we should de-register from that focus manager now. |
| 842 if (GetWidget() && accelerator_focus_manager_) | 842 if (GetWidget() && accelerator_focus_manager_) |
| 843 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this); | 843 accelerator_focus_manager_->UnregisterAccelerator(accelerator, this); |
| 844 } | 844 } |
| 845 | 845 |
| 846 void View::ResetAccelerators() { | 846 void View::ResetAccelerators() { |
| 847 if (accelerators_.get()) | 847 if (accelerators_.get()) |
| 848 UnregisterAccelerators(false); | 848 UnregisterAccelerators(false); |
| 849 } | 849 } |
| 850 | 850 |
| 851 bool View::AcceleratorPressed(const Accelerator& accelerator) { | 851 bool View::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 852 return false; | 852 return false; |
| 853 } | 853 } |
| 854 | 854 |
| 855 // Focus ----------------------------------------------------------------------- | 855 // Focus ----------------------------------------------------------------------- |
| 856 | 856 |
| 857 bool View::HasFocus() const { | 857 bool View::HasFocus() const { |
| 858 const FocusManager* focus_manager = GetFocusManager(); | 858 const FocusManager* focus_manager = GetFocusManager(); |
| 859 return focus_manager && (focus_manager->GetFocusedView() == this); | 859 return focus_manager && (focus_manager->GetFocusedView() == this); |
| 860 } | 860 } |
| 861 | 861 |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 // NOTREACHED assertion and verify accelerators works as | 1954 // NOTREACHED assertion and verify accelerators works as |
| 1955 // expected. | 1955 // expected. |
| 1956 #if defined(OS_WIN) | 1956 #if defined(OS_WIN) |
| 1957 NOTREACHED(); | 1957 NOTREACHED(); |
| 1958 #endif | 1958 #endif |
| 1959 return; | 1959 return; |
| 1960 } | 1960 } |
| 1961 // Only register accelerators if we are visible. | 1961 // Only register accelerators if we are visible. |
| 1962 if (!IsVisibleInRootView() || !GetWidget()->IsVisible()) | 1962 if (!IsVisibleInRootView() || !GetWidget()->IsVisible()) |
| 1963 return; | 1963 return; |
| 1964 for (std::vector<Accelerator>::const_iterator i( | 1964 for (std::vector<ui::Accelerator>::const_iterator i( |
| 1965 accelerators_->begin() + registered_accelerator_count_); | 1965 accelerators_->begin() + registered_accelerator_count_); |
| 1966 i != accelerators_->end(); ++i) { | 1966 i != accelerators_->end(); ++i) { |
| 1967 accelerator_focus_manager_->RegisterAccelerator(*i, this); | 1967 accelerator_focus_manager_->RegisterAccelerator(*i, this); |
| 1968 } | 1968 } |
| 1969 registered_accelerator_count_ = accelerators_->size(); | 1969 registered_accelerator_count_ = accelerators_->size(); |
| 1970 } | 1970 } |
| 1971 | 1971 |
| 1972 void View::UnregisterAccelerators(bool leave_data_intact) { | 1972 void View::UnregisterAccelerators(bool leave_data_intact) { |
| 1973 if (!accelerators_.get()) | 1973 if (!accelerators_.get()) |
| 1974 return; | 1974 return; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2067 | 2067 |
| 2068 OSExchangeData data; | 2068 OSExchangeData data; |
| 2069 WriteDragData(press_pt, &data); | 2069 WriteDragData(press_pt, &data); |
| 2070 | 2070 |
| 2071 // Message the RootView to do the drag and drop. That way if we're removed | 2071 // Message the RootView to do the drag and drop. That way if we're removed |
| 2072 // the RootView can detect it and avoid calling us back. | 2072 // the RootView can detect it and avoid calling us back. |
| 2073 GetWidget()->RunShellDrag(this, data, drag_operations); | 2073 GetWidget()->RunShellDrag(this, data, drag_operations); |
| 2074 } | 2074 } |
| 2075 | 2075 |
| 2076 } // namespace views | 2076 } // namespace views |
| OLD | NEW |