Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: views/controls/tabbed_pane/tabbed_pane.cc

Issue 8658009: views: Move tabbed_pane directory to ui/views/controls/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix native_tabbed_pane_wrapper.h Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "views/controls/tabbed_pane/tabbed_pane.h"
6
7 #include "base/logging.h"
8 #include "ui/base/accessibility/accessible_view_state.h"
9 #include "ui/base/keycodes/keyboard_codes.h"
10 #include "ui/views/widget/widget.h"
11 #include "views/controls/native/native_view_host.h"
12 #include "views/controls/tabbed_pane/native_tabbed_pane_wrapper.h"
13 #include "views/controls/tabbed_pane/tabbed_pane_listener.h"
14
15 namespace views {
16
17 // static
18 const char TabbedPane::kViewClassName[] = "views/TabbedPane";
19
20 TabbedPane::TabbedPane() : native_tabbed_pane_(NULL), listener_(NULL) {
21 set_focusable(true);
22 }
23
24 TabbedPane::~TabbedPane() {
25 }
26
27 int TabbedPane::GetTabCount() {
28 return native_tabbed_pane_->GetTabCount();
29 }
30
31 int TabbedPane::GetSelectedTabIndex() {
32 return native_tabbed_pane_->GetSelectedTabIndex();
33 }
34
35 View* TabbedPane::GetSelectedTab() {
36 return native_tabbed_pane_->GetSelectedTab();
37 }
38
39 void TabbedPane::AddTab(const string16& title, View* contents) {
40 native_tabbed_pane_->AddTab(title, contents);
41 PreferredSizeChanged();
42 }
43
44 void TabbedPane::AddTabAtIndex(int index,
45 const string16& title,
46 View* contents,
47 bool select_if_first_tab) {
48 native_tabbed_pane_->AddTabAtIndex(index, title, contents,
49 select_if_first_tab);
50 PreferredSizeChanged();
51 }
52
53 View* TabbedPane::RemoveTabAtIndex(int index) {
54 View* tab = native_tabbed_pane_->RemoveTabAtIndex(index);
55 PreferredSizeChanged();
56 return tab;
57 }
58
59 void TabbedPane::SelectTabAt(int index) {
60 native_tabbed_pane_->SelectTabAt(index);
61 }
62
63 void TabbedPane::SetAccessibleName(const string16& name) {
64 accessible_name_ = name;
65 }
66
67 gfx::Size TabbedPane::GetPreferredSize() {
68 return native_tabbed_pane_ ?
69 native_tabbed_pane_->GetPreferredSize() : gfx::Size();
70 }
71
72 void TabbedPane::LoadAccelerators() {
73 // Ctrl+Shift+Tab
74 AddAccelerator(ui::Accelerator(ui::VKEY_TAB, true, true, false));
75 // Ctrl+Tab
76 AddAccelerator(ui::Accelerator(ui::VKEY_TAB, false, true, false));
77 }
78
79 void TabbedPane::Layout() {
80 if (native_tabbed_pane_)
81 native_tabbed_pane_->GetView()->SetBounds(0, 0, width(), height());
82 }
83
84 void TabbedPane::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
85 if (is_add && !native_tabbed_pane_) {
86 // The native wrapper's lifetime will be managed by the view hierarchy after
87 // we call AddChildView.
88 native_tabbed_pane_ = NativeTabbedPaneWrapper::CreateNativeWrapper(this);
89 AddChildView(native_tabbed_pane_->GetView());
90 LoadAccelerators();
91 }
92 }
93
94 bool TabbedPane::AcceleratorPressed(const ui::Accelerator& accelerator) {
95 // We only accept Ctrl+Tab keyboard events.
96 DCHECK(accelerator.key_code() == ui::VKEY_TAB && accelerator.IsCtrlDown());
97
98 int tab_count = GetTabCount();
99 if (tab_count <= 1)
100 return false;
101 int selected_tab_index = GetSelectedTabIndex();
102 int next_tab_index = accelerator.IsShiftDown() ?
103 (selected_tab_index - 1) % tab_count :
104 (selected_tab_index + 1) % tab_count;
105 // Wrap around.
106 if (next_tab_index < 0)
107 next_tab_index += tab_count;
108 SelectTabAt(next_tab_index);
109 return true;
110 }
111
112 std::string TabbedPane::GetClassName() const {
113 return kViewClassName;
114 }
115
116 void TabbedPane::OnFocus() {
117 // Forward the focus to the wrapper.
118 if (native_tabbed_pane_) {
119 native_tabbed_pane_->SetFocus();
120
121 View* selected_tab = GetSelectedTab();
122 if (selected_tab) {
123 selected_tab->GetWidget()->NotifyAccessibilityEvent(
124 selected_tab, ui::AccessibilityTypes::EVENT_FOCUS, true);
125 }
126 } else {
127 View::OnFocus(); // Will focus the RootView window (so we still get
128 // keyboard messages).
129 }
130 }
131
132 void TabbedPane::OnPaintFocusBorder(gfx::Canvas* canvas) {
133 if (NativeViewHost::kRenderNativeControlFocus)
134 View::OnPaintFocusBorder(canvas);
135 }
136
137 void TabbedPane::GetAccessibleState(ui::AccessibleViewState* state) {
138 state->role = ui::AccessibilityTypes::ROLE_PAGETABLIST;
139 state->name = accessible_name_;
140 }
141
142 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/tabbed_pane/tabbed_pane.h ('k') | views/controls/tabbed_pane/tabbed_pane_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698