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

Side by Side Diff: ui/views/controls/separator.cc

Issue 2675983003: views::Separator cleanup. (Closed)
Patch Set: update docs 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
« ui/views/controls/separator.h ('K') | « ui/views/controls/separator.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/separator.h" 5 #include "ui/views/controls/separator.h"
6 6
7 #include "ui/accessibility/ax_node_data.h" 7 #include "ui/accessibility/ax_node_data.h"
8 #include "ui/gfx/canvas.h" 8 #include "ui/gfx/canvas.h"
9 #include "ui/native_theme/native_theme.h" 9 #include "ui/native_theme/native_theme.h"
10 10
11 namespace views { 11 namespace views {
12 12
13 // static 13 // static
14 const char Separator::kViewClassName[] = "Separator"; 14 const char Separator::kViewClassName[] = "Separator";
15 15
16 // The separator size in pixels. 16 // static
17 const int kSeparatorSize = 1; 17 const int Separator::kThickness = 1;
18 18
19 Separator::Separator(Orientation orientation) 19 Separator::Separator(Orientation orientation) : orientation_(orientation) {}
20 : orientation_(orientation),
21 color_overridden_(false),
22 size_(kSeparatorSize) {
23 SetColorFromNativeTheme();
24 }
25 20
26 Separator::~Separator() { 21 Separator::~Separator() {}
27 }
28 22
29 void Separator::SetColor(SkColor color) { 23 void Separator::SetColor(SkColor color) {
30 color_ = color; 24 overridden_color_ = color;
31 color_overridden_ = true;
32 SchedulePaint(); 25 SchedulePaint();
33 } 26 }
34 27
35 void Separator::SetPreferredSize(int size) { 28 void Separator::SetPreferredLength(int length) {
36 if (size != size_) { 29 if (length != length_) {
37 size_ = size; 30 length_ = length;
38 PreferredSizeChanged(); 31 PreferredSizeChanged();
39 } 32 }
40 } 33 }
41 34
42 void Separator::SetColorFromNativeTheme() {
43 color_ = GetNativeTheme()->GetSystemColor(
44 ui::NativeTheme::kColorId_SeparatorColor);
45 }
46
47 //////////////////////////////////////////////////////////////////////////////// 35 ////////////////////////////////////////////////////////////////////////////////
48 // Separator, View overrides: 36 // Separator, View overrides:
49 37
50 gfx::Size Separator::GetPreferredSize() const { 38 gfx::Size Separator::GetPreferredSize() const {
51 gfx::Size size = 39 gfx::Size size = orientation_ == HORIZONTAL ? gfx::Size(length_, kThickness)
tdanderson 2017/02/06 21:19:06 You're switching the meaning of HORIZONTAL vs VERT
Evan Stade 2017/02/06 21:39:17 The meaning of horizontal and vertical are the sam
sky 2017/02/07 19:02:49 I see where you are going. I find the change to se
Evan Stade 2017/02/07 21:39:50 I looked into this but it's not convenient to actu
52 orientation_ == HORIZONTAL ? gfx::Size(1, size_) : gfx::Size(size_, 1); 40 : gfx::Size(kThickness, length_);
53 gfx::Insets insets = GetInsets(); 41 gfx::Insets insets = GetInsets();
54 size.Enlarge(insets.width(), insets.height()); 42 size.Enlarge(insets.width(), insets.height());
55 return size; 43 return size;
56 } 44 }
57 45
58 void Separator::GetAccessibleNodeData(ui::AXNodeData* node_data) { 46 void Separator::GetAccessibleNodeData(ui::AXNodeData* node_data) {
59 node_data->role = ui::AX_ROLE_SPLITTER; 47 node_data->role = ui::AX_ROLE_SPLITTER;
60 } 48 }
61 49
62 void Separator::OnPaint(gfx::Canvas* canvas) { 50 void Separator::OnPaint(gfx::Canvas* canvas) {
63 canvas->FillRect(GetContentsBounds(), color_); 51 SkColor color = overridden_color_
64 } 52 ? *overridden_color_
53 : GetNativeTheme()->GetSystemColor(
54 ui::NativeTheme::kColorId_SeparatorColor);
65 55
66 void Separator::OnNativeThemeChanged(const ui::NativeTheme* theme) { 56 // The separator fills its bounds, but avoid filling partial pixels.
sky 2017/02/03 23:49:45 Are you sure this is the right thing? As views don
Evan Stade 2017/02/06 16:31:26 yes. Before/after screenshot posted to bug. If the
sky 2017/02/06 17:59:21 Do we need to turn on aa?
Evan Stade 2017/02/06 19:03:29 We want an integral number of pixels. AA would giv
sky 2017/02/06 22:42:55 I think we're going in circles. We really need vie
Evan Stade 2017/02/07 16:57:54 Yea, but I thought that was a long way off from be
67 if (!color_overridden_) 57 float dsf = canvas->UndoDeviceScaleFactor();
68 SetColorFromNativeTheme(); 58 gfx::RectF contents = gfx::ScaleRect(gfx::RectF(GetContentsBounds()), dsf);
59 canvas->FillRect(gfx::ToEnclosedRect(contents), color);
69 } 60 }
70 61
71 const char* Separator::GetClassName() const { 62 const char* Separator::GetClassName() const {
72 return kViewClassName; 63 return kViewClassName;
73 } 64 }
74 65
75 } // namespace views 66 } // namespace views
OLDNEW
« ui/views/controls/separator.h ('K') | « ui/views/controls/separator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698