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

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

Issue 2675983003: views::Separator cleanup. (Closed)
Patch Set: fix another callsite 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() : preferred_size_(kThickness, kThickness) {}
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::SetPreferredWidth(int width) {
36 if (size != size_) { 29 if (width == preferred_size_.width())
sky 2017/02/09 03:16:09 WDYT of calling a common (private) SetPreferredSiz
Evan Stade 2017/02/09 15:46:11 I was on the fence about creating a shared private
sky 2017/02/09 20:32:50 I'm ok with only what we need and no note. If some
37 size_ = size; 30 return;
38 PreferredSizeChanged(); 31
39 } 32 preferred_size_ = gfx::Size(width, kThickness);
33 PreferredSizeChanged();
40 } 34 }
41 35
42 void Separator::SetColorFromNativeTheme() { 36 void Separator::SetPreferredHeight(int height) {
43 color_ = GetNativeTheme()->GetSystemColor( 37 if (height == preferred_size_.height())
44 ui::NativeTheme::kColorId_SeparatorColor); 38 return;
39
40 preferred_size_ = gfx::Size(kThickness, height);
41 PreferredSizeChanged();
45 } 42 }
46 43
47 //////////////////////////////////////////////////////////////////////////////// 44 ////////////////////////////////////////////////////////////////////////////////
48 // Separator, View overrides: 45 // Separator, View overrides:
49 46
50 gfx::Size Separator::GetPreferredSize() const { 47 gfx::Size Separator::GetPreferredSize() const {
51 gfx::Size size = 48 gfx::Size size = preferred_size_;
52 orientation_ == HORIZONTAL ? gfx::Size(1, size_) : gfx::Size(size_, 1);
53 gfx::Insets insets = GetInsets(); 49 gfx::Insets insets = GetInsets();
54 size.Enlarge(insets.width(), insets.height()); 50 size.Enlarge(insets.width(), insets.height());
55 return size; 51 return size;
56 } 52 }
57 53
58 void Separator::GetAccessibleNodeData(ui::AXNodeData* node_data) { 54 void Separator::GetAccessibleNodeData(ui::AXNodeData* node_data) {
59 node_data->role = ui::AX_ROLE_SPLITTER; 55 node_data->role = ui::AX_ROLE_SPLITTER;
60 } 56 }
61 57
62 void Separator::OnPaint(gfx::Canvas* canvas) { 58 void Separator::OnPaint(gfx::Canvas* canvas) {
63 canvas->FillRect(GetContentsBounds(), color_); 59 SkColor color = overridden_color_
64 } 60 ? *overridden_color_
61 : GetNativeTheme()->GetSystemColor(
62 ui::NativeTheme::kColorId_SeparatorColor);
65 63
66 void Separator::OnNativeThemeChanged(const ui::NativeTheme* theme) { 64 // The separator fills its bounds, but avoid filling partial pixels.
67 if (!color_overridden_) 65 float dsf = canvas->UndoDeviceScaleFactor();
68 SetColorFromNativeTheme(); 66 gfx::RectF contents = gfx::ScaleRect(gfx::RectF(GetContentsBounds()), dsf);
67 canvas->FillRect(gfx::ToEnclosedRect(contents), color);
69 } 68 }
70 69
71 const char* Separator::GetClassName() const { 70 const char* Separator::GetClassName() const {
72 return kViewClassName; 71 return kViewClassName;
73 } 72 }
74 73
75 } // namespace views 74 } // 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