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

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

Issue 2675983003: views::Separator cleanup. (Closed)
Patch Set: revert test change 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 | « 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() {}
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::SetPreferredHeight(int height) {
36 if (size != size_) { 29 preferred_height_ = height;
37 size_ = size; 30 PreferredSizeChanged();
38 PreferredSizeChanged();
39 }
40 }
41
42 void Separator::SetColorFromNativeTheme() {
43 color_ = GetNativeTheme()->GetSystemColor(
44 ui::NativeTheme::kColorId_SeparatorColor);
45 } 31 }
46 32
47 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
48 // Separator, View overrides: 34 // Separator, View overrides:
49 35
50 gfx::Size Separator::GetPreferredSize() const { 36 gfx::Size Separator::GetPreferredSize() const {
51 gfx::Size size = 37 gfx::Size size(kThickness, preferred_height_);
52 orientation_ == HORIZONTAL ? gfx::Size(1, size_) : gfx::Size(size_, 1);
53 gfx::Insets insets = GetInsets(); 38 gfx::Insets insets = GetInsets();
54 size.Enlarge(insets.width(), insets.height()); 39 size.Enlarge(insets.width(), insets.height());
55 return size; 40 return size;
56 } 41 }
57 42
58 void Separator::GetAccessibleNodeData(ui::AXNodeData* node_data) { 43 void Separator::GetAccessibleNodeData(ui::AXNodeData* node_data) {
59 node_data->role = ui::AX_ROLE_SPLITTER; 44 node_data->role = ui::AX_ROLE_SPLITTER;
60 } 45 }
61 46
62 void Separator::OnPaint(gfx::Canvas* canvas) { 47 void Separator::OnPaint(gfx::Canvas* canvas) {
63 canvas->FillRect(GetContentsBounds(), color_); 48 SkColor color = overridden_color_
64 } 49 ? *overridden_color_
50 : GetNativeTheme()->GetSystemColor(
51 ui::NativeTheme::kColorId_SeparatorColor);
65 52
66 void Separator::OnNativeThemeChanged(const ui::NativeTheme* theme) { 53 // The separator fills its bounds, but avoid filling partial pixels.
67 if (!color_overridden_) 54 float dsf = canvas->UndoDeviceScaleFactor();
68 SetColorFromNativeTheme(); 55 gfx::RectF contents = gfx::ScaleRect(gfx::RectF(GetContentsBounds()), dsf);
56 canvas->FillRect(gfx::ToEnclosedRect(contents), color);
69 } 57 }
70 58
71 const char* Separator::GetClassName() const { 59 const char* Separator::GetClassName() const {
72 return kViewClassName; 60 return kViewClassName;
73 } 61 }
74 62
75 } // namespace views 63 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/separator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698