OLD | NEW |
---|---|
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 Loading... | |
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 bool was_empty_selection = (selected_node_ == NULL); | 225 bool was_empty_selection = (selected_node_ == NULL); |
223 bool changed = (selected_node_ != node); | 226 bool changed = (selected_node_ != node); |
224 if (changed) { | 227 if (changed) { |
225 SchedulePaintForNode(selected_node_); | 228 SchedulePaintForNode(selected_node_); |
226 selected_node_ = node; | 229 selected_node_ = node; |
227 if (selected_node_ == &root_ && !root_shown_) | 230 if (selected_node_ == &root_ && !root_shown_) |
228 selected_node_ = NULL; | 231 selected_node_ = NULL; |
229 if (selected_node_ && selected_node_ != &root_) | 232 if (selected_node_ && selected_node_ != &root_) |
230 Expand(model_->GetParent(selected_node_->model_node())); | 233 Expand(model_->GetParent(selected_node_->model_node())); |
231 SchedulePaintForNode(selected_node_); | 234 SchedulePaintForNode(selected_node_); |
235 | |
236 // TODO(dmazzoni): Decide if EVENT_SELECTION_CHANGED is a better choice for | |
237 // sub-item selection event. | |
238 NotifyAccessibilityEvent(ui::AccessibilityTypes::EVENT_FOCUS, true); | |
sky
2013/11/24 18:58:28
Can you move this to the end of the function. I wo
zel
2013/12/02 05:36:10
Done.
| |
232 } | 239 } |
233 | 240 |
234 if (selected_node_) | 241 if (selected_node_) |
235 ScrollRectToVisible(GetBoundsForNode(selected_node_)); | 242 ScrollRectToVisible(GetBoundsForNode(selected_node_)); |
236 | 243 |
237 // Notify controller if the old selection was empty to handle the case of | 244 // Notify controller if the old selection was empty to handle the case of |
238 // remove explicitly resetting selected_node_ before invoking this. | 245 // remove explicitly resetting selected_node_ before invoking this. |
239 if (controller_ && (changed || was_empty_selection)) | 246 if (controller_ && (changed || was_empty_selection)) |
240 controller_->OnTreeViewSelectionChanged(this); | 247 controller_->OnTreeViewSelectionChanged(this); |
241 } | 248 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 gfx::Rect bounds(GetBoundsForNodeImpl(node, row, depth)); | 397 gfx::Rect bounds(GetBoundsForNodeImpl(node, row, depth)); |
391 if (!bounds.Contains(local_point)) | 398 if (!bounds.Contains(local_point)) |
392 return; | 399 return; |
393 } | 400 } |
394 View::ShowContextMenu(p, source_type); | 401 View::ShowContextMenu(p, source_type); |
395 } | 402 } |
396 | 403 |
397 void TreeView::GetAccessibleState(ui::AccessibleViewState* state) { | 404 void TreeView::GetAccessibleState(ui::AccessibleViewState* state) { |
398 state->role = ui::AccessibilityTypes::ROLE_OUTLINE; | 405 state->role = ui::AccessibilityTypes::ROLE_OUTLINE; |
399 state->state = ui::AccessibilityTypes::STATE_READONLY; | 406 state->state = ui::AccessibilityTypes::STATE_READONLY; |
407 if (!selected_node_ || !selected_node_->model_node()) | |
sky
2013/11/24 18:58:28
The second null check isn't necessary.
zel
2013/12/02 05:36:10
Done.
| |
408 return; | |
409 | |
410 // Get selected item info. | |
411 state->role = ui::AccessibilityTypes::ROLE_OUTLINEITEM; | |
412 state->name = selected_node_->model_node()->GetTitle(); | |
413 } | |
414 | |
415 const char* TreeView::GetClassName() const { | |
416 return kViewClassName; | |
400 } | 417 } |
401 | 418 |
402 void TreeView::TreeNodesAdded(TreeModel* model, | 419 void TreeView::TreeNodesAdded(TreeModel* model, |
403 TreeModelNode* parent, | 420 TreeModelNode* parent, |
404 int start, | 421 int start, |
405 int count) { | 422 int count) { |
406 InternalNode* parent_node = | 423 InternalNode* parent_node = |
407 GetInternalNodeForModelNode(parent, DONT_CREATE_IF_NOT_LOADED); | 424 GetInternalNodeForModelNode(parent, DONT_CREATE_IF_NOT_LOADED); |
408 if (!parent_node || !parent_node->loaded_children()) | 425 if (!parent_node || !parent_node->loaded_children()) |
409 return; | 426 return; |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 if (!is_expanded_) | 1031 if (!is_expanded_) |
1015 return max_width; | 1032 return max_width; |
1016 for (int i = 0; i < child_count(); ++i) { | 1033 for (int i = 0; i < child_count(); ++i) { |
1017 max_width = std::max(max_width, | 1034 max_width = std::max(max_width, |
1018 GetChild(i)->GetMaxWidth(indent, depth + 1)); | 1035 GetChild(i)->GetMaxWidth(indent, depth + 1)); |
1019 } | 1036 } |
1020 return max_width; | 1037 return max_width; |
1021 } | 1038 } |
1022 | 1039 |
1023 } // namespace views | 1040 } // namespace views |
OLD | NEW |