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

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

Issue 2694323003: Reuse submenu arrow images for trees (like the edit bookmark tree). (Closed)
Patch Set: Created 3 years, 10 months 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
« no previous file with comments | « no previous file | 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/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "ui/accessibility/ax_node_data.h" 12 #include "ui/accessibility/ax_node_data.h"
13 #include "ui/base/ime/input_method.h" 13 #include "ui/base/ime/input_method.h"
14 #include "ui/base/material_design/material_design_controller.h" 14 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/base/resource/resource_bundle.h" 15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/events/event.h" 16 #include "ui/events/event.h"
17 #include "ui/events/keycodes/keyboard_codes.h" 17 #include "ui/events/keycodes/keyboard_codes.h"
18 #include "ui/gfx/canvas.h" 18 #include "ui/gfx/canvas.h"
19 #include "ui/gfx/color_utils.h"
19 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
20 #include "ui/gfx/geometry/rect_conversions.h" 21 #include "ui/gfx/geometry/rect_conversions.h"
21 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
23 #include "ui/gfx/image/image_skia_operations.h"
24 #include "ui/gfx/paint_vector_icon.h"
22 #include "ui/gfx/skia_util.h" 25 #include "ui/gfx/skia_util.h"
23 #include "ui/native_theme/native_theme.h" 26 #include "ui/native_theme/native_theme.h"
24 #include "ui/resources/grit/ui_resources.h" 27 #include "ui/resources/grit/ui_resources.h"
25 #include "ui/views/controls/focus_ring.h" 28 #include "ui/views/controls/focus_ring.h"
26 #include "ui/views/controls/prefix_selector.h" 29 #include "ui/views/controls/prefix_selector.h"
27 #include "ui/views/controls/scroll_view.h" 30 #include "ui/views/controls/scroll_view.h"
28 #include "ui/views/controls/textfield/textfield.h" 31 #include "ui/views/controls/textfield/textfield.h"
29 #include "ui/views/controls/tree/tree_view_controller.h" 32 #include "ui/views/controls/tree/tree_view_controller.h"
30 #include "ui/views/resources/grit/views_resources.h" 33 #include "ui/views/resources/grit/views_resources.h"
31 #include "ui/views/style/platform_style.h" 34 #include "ui/views/style/platform_style.h"
35 #include "ui/views/vector_icons.h"
32 36
33 using ui::TreeModel; 37 using ui::TreeModel;
34 using ui::TreeModelNode; 38 using ui::TreeModelNode;
35 39
36 namespace views { 40 namespace views {
37 41
38 // Insets around the view. 42 // Insets around the view.
39 static const int kHorizontalInset = 2; 43 static const int kHorizontalInset = 2;
40 static const int kVerticalInset = 2; 44 static const int kVerticalInset = 2;
41 // Padding before/after the image. 45 // Padding before/after the image.
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 text_bounds.width() - kTextHorizontalPadding * 2, 820 text_bounds.width() - kTextHorizontalPadding * 2,
817 text_bounds.height() - kTextVerticalPadding * 2); 821 text_bounds.height() - kTextVerticalPadding * 2);
818 canvas->DrawStringRect(node->model_node()->GetTitle(), font_list_, 822 canvas->DrawStringRect(node->model_node()->GetTitle(), font_list_,
819 GetNativeTheme()->GetSystemColor(color_id), 823 GetNativeTheme()->GetSystemColor(color_id),
820 internal_bounds); 824 internal_bounds);
821 } 825 }
822 826
823 void TreeView::PaintExpandControl(gfx::Canvas* canvas, 827 void TreeView::PaintExpandControl(gfx::Canvas* canvas,
824 const gfx::Rect& node_bounds, 828 const gfx::Rect& node_bounds,
825 bool expanded) { 829 bool expanded) {
826 int center_x; 830 gfx::ImageSkia arrow = gfx::CreateVectorIcon(
827 if (base::i18n::IsRTL()) { 831 kSubmenuArrowIcon,
828 center_x = node_bounds.right() - kArrowRegionSize + 832 color_utils::DeriveDefaultIconColor(
829 (kArrowRegionSize - 4) / 2; 833 GetNativeTheme()->GetSystemColor(text_color_id(false, false))));
Peter Kasting 2017/02/15 01:05:31 Any particular reason to move away from kColorId_T
Evan Stade 2017/02/15 01:28:58 Ah, forgot about that color. I think we should rem
Evan Stade 2017/02/15 16:07:37 done
830 } else { 834 if (expanded) {
831 center_x = node_bounds.x() + (kArrowRegionSize - 4) / 2; 835 arrow = gfx::ImageSkiaOperations::CreateRotatedImage(
836 arrow, base::i18n::IsRTL() ? SkBitmapOperations::ROTATION_270_CW
837 : SkBitmapOperations::ROTATION_90_CW);
832 } 838 }
833 int center_y = node_bounds.y() + node_bounds.height() / 2; 839 gfx::Rect arrow_bounds = node_bounds;
834 const SkColor arrow_color = GetNativeTheme()->GetSystemColor( 840 arrow_bounds.Inset(gfx::Insets((node_bounds.height() - arrow.height()) / 2,
835 ui::NativeTheme::kColorId_TreeArrow); 841 (kArrowRegionSize - arrow.width()) / 2));
836 // TODO: this should come from an image. 842 canvas->DrawImageInt(arrow, base::i18n::IsRTL()
837 if (!expanded) { 843 ? arrow_bounds.right() - arrow.width()
838 int delta = base::i18n::IsRTL() ? 1 : -1; 844 : arrow_bounds.x(),
839 for (int i = 0; i < 4; ++i) { 845 arrow_bounds.y());
Peter Kasting 2017/02/15 01:05:31 Nit: I think this is equivalent, and seems shorter
Evan Stade 2017/02/15 01:28:58 the arrow square isn't centered in the node bounds
Peter Kasting 2017/02/15 02:05:28 I know. The code I wrote won't center it in the n
840 canvas->FillRect(gfx::Rect(center_x + delta * (2 - i),
841 center_y - (3 - i), 1, (3 - i) * 2 + 1),
842 arrow_color);
843 }
844 } else {
845 center_y -= 2;
846 for (int i = 0; i < 4; ++i) {
847 canvas->FillRect(gfx::Rect(center_x - (3 - i), center_y + i,
848 (3 - i) * 2 + 1, 1), arrow_color);
849 }
850 }
851 } 846 }
852 847
853 TreeView::InternalNode* TreeView::GetInternalNodeForModelNode( 848 TreeView::InternalNode* TreeView::GetInternalNodeForModelNode(
854 ui::TreeModelNode* model_node, 849 ui::TreeModelNode* model_node,
855 GetInternalNodeCreateType create_type) { 850 GetInternalNodeCreateType create_type) {
856 if (model_node == root_.model_node()) 851 if (model_node == root_.model_node())
857 return &root_; 852 return &root_;
858 InternalNode* parent_internal_node = 853 InternalNode* parent_internal_node =
859 GetInternalNodeForModelNode(model_->GetParent(model_node), create_type); 854 GetInternalNodeForModelNode(model_->GetParent(model_node), create_type);
860 if (!parent_internal_node) 855 if (!parent_internal_node)
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 if (!is_expanded_) 1106 if (!is_expanded_)
1112 return max_width; 1107 return max_width;
1113 for (int i = 0; i < child_count(); ++i) { 1108 for (int i = 0; i < child_count(); ++i) {
1114 max_width = std::max(max_width, 1109 max_width = std::max(max_width,
1115 GetChild(i)->GetMaxWidth(indent, depth + 1)); 1110 GetChild(i)->GetMaxWidth(indent, depth + 1));
1116 } 1111 }
1117 return max_width; 1112 return max_width;
1118 } 1113 }
1119 1114
1120 } // namespace views 1115 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698