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

Side by Side Diff: ui/views/controls/tree/tree_view.cc

Issue 79543010: Added basic accessibility to TreeView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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
« no previous file with comments | « ui/views/controls/tree/tree_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/controls/tree/tree_view.h" 5 #include "ui/views/controls/tree/tree_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 24 matching lines...) Expand all
35 // Padding before/after the image. 35 // Padding before/after the image.
36 static const int kImagePadding = 4; 36 static const int kImagePadding = 4;
37 // Size of the arrow region. 37 // Size of the arrow region.
38 static const int kArrowRegionSize = 12; 38 static const int kArrowRegionSize = 12;
39 // Padding around the text (on each side). 39 // Padding around the text (on each side).
40 static const int kTextVerticalPadding = 3; 40 static const int kTextVerticalPadding = 3;
41 static const int kTextHorizontalPadding = 2; 41 static const int kTextHorizontalPadding = 2;
42 // How much children are indented from their parent. 42 // How much children are indented from their parent.
43 static const int kIndent = 20; 43 static const int kIndent = 20;
44 44
45 // static
46 const char TreeView::kViewClassName[] = "TreeView";
47
45 namespace { 48 namespace {
46 49
47 // Returns the color id for the background of selected text. |has_focus| 50 // Returns the color id for the background of selected text. |has_focus|
48 // indicates if the tree has focus. 51 // indicates if the tree has focus.
49 ui::NativeTheme::ColorId text_background_color_id(bool has_focus) { 52 ui::NativeTheme::ColorId text_background_color_id(bool has_focus) {
50 return has_focus ? 53 return has_focus ?
51 ui::NativeTheme::kColorId_TreeSelectionBackgroundFocused : 54 ui::NativeTheme::kColorId_TreeSelectionBackgroundFocused :
52 ui::NativeTheme::kColorId_TreeSelectionBackgroundUnfocused; 55 ui::NativeTheme::kColorId_TreeSelectionBackgroundUnfocused;
53 } 56 }
54 57
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 SchedulePaintForNode(selected_node_); 234 SchedulePaintForNode(selected_node_);
232 } 235 }
233 236
234 if (selected_node_) 237 if (selected_node_)
235 ScrollRectToVisible(GetBoundsForNode(selected_node_)); 238 ScrollRectToVisible(GetBoundsForNode(selected_node_));
236 239
237 // Notify controller if the old selection was empty to handle the case of 240 // Notify controller if the old selection was empty to handle the case of
238 // remove explicitly resetting selected_node_ before invoking this. 241 // remove explicitly resetting selected_node_ before invoking this.
239 if (controller_ && (changed || was_empty_selection)) 242 if (controller_ && (changed || was_empty_selection))
240 controller_->OnTreeViewSelectionChanged(this); 243 controller_->OnTreeViewSelectionChanged(this);
244
245 if (changed) {
246 // TODO(dmazzoni): Decide if EVENT_SELECTION_CHANGED is a better choice for
247 // sub-item selection event.
248 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_FOCUS, true);
249 }
241 } 250 }
242 251
243 TreeModelNode* TreeView::GetSelectedNode() { 252 TreeModelNode* TreeView::GetSelectedNode() {
244 return selected_node_ ? selected_node_->model_node() : NULL; 253 return selected_node_ ? selected_node_->model_node() : NULL;
245 } 254 }
246 255
247 void TreeView::Collapse(ui::TreeModelNode* model_node) { 256 void TreeView::Collapse(ui::TreeModelNode* model_node) {
248 // Don't collapse the root if the root isn't shown, otherwise nothing is 257 // Don't collapse the root if the root isn't shown, otherwise nothing is
249 // displayed. 258 // displayed.
250 if (model_node == root_.model_node() && !root_shown_) 259 if (model_node == root_.model_node() && !root_shown_)
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 gfx::Rect bounds(GetBoundsForNodeImpl(node, row, depth)); 399 gfx::Rect bounds(GetBoundsForNodeImpl(node, row, depth));
391 if (!bounds.Contains(local_point)) 400 if (!bounds.Contains(local_point))
392 return; 401 return;
393 } 402 }
394 View::ShowContextMenu(p, source_type); 403 View::ShowContextMenu(p, source_type);
395 } 404 }
396 405
397 void TreeView::GetAccessibleState(ui::AccessibleViewState* state) { 406 void TreeView::GetAccessibleState(ui::AccessibleViewState* state) {
398 state->role = ui::AccessibilityTypes::ROLE_OUTLINE; 407 state->role = ui::AccessibilityTypes::ROLE_OUTLINE;
399 state->state = ui::AccessibilityTypes::STATE_READONLY; 408 state->state = ui::AccessibilityTypes::STATE_READONLY;
409 if (!selected_node_)
410 return;
411
412 // Get selected item info.
413 state->role = ui::AccessibilityTypes::ROLE_OUTLINEITEM;
414 state->name = selected_node_->model_node()->GetTitle();
415 }
416
417 const char* TreeView::GetClassName() const {
418 return kViewClassName;
400 } 419 }
401 420
402 void TreeView::TreeNodesAdded(TreeModel* model, 421 void TreeView::TreeNodesAdded(TreeModel* model,
403 TreeModelNode* parent, 422 TreeModelNode* parent,
404 int start, 423 int start,
405 int count) { 424 int count) {
406 InternalNode* parent_node = 425 InternalNode* parent_node =
407 GetInternalNodeForModelNode(parent, DONT_CREATE_IF_NOT_LOADED); 426 GetInternalNodeForModelNode(parent, DONT_CREATE_IF_NOT_LOADED);
408 if (!parent_node || !parent_node->loaded_children()) 427 if (!parent_node || !parent_node->loaded_children())
409 return; 428 return;
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 if (!is_expanded_) 1033 if (!is_expanded_)
1015 return max_width; 1034 return max_width;
1016 for (int i = 0; i < child_count(); ++i) { 1035 for (int i = 0; i < child_count(); ++i) {
1017 max_width = std::max(max_width, 1036 max_width = std::max(max_width,
1018 GetChild(i)->GetMaxWidth(indent, depth + 1)); 1037 GetChild(i)->GetMaxWidth(indent, depth + 1));
1019 } 1038 }
1020 return max_width; 1039 return max_width;
1021 } 1040 }
1022 1041
1023 } // namespace views 1042 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/tree/tree_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698