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

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

Issue 2623753002: Native themes: Add separator color (Closed)
Patch Set: Change function order Created 3 years, 11 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 10
10 namespace views { 11 namespace views {
11 12
12 // static 13 // static
13 const char Separator::kViewClassName[] = "Separator"; 14 const char Separator::kViewClassName[] = "Separator";
14 15
15 // The separator size in pixels. 16 // The separator size in pixels.
16 const int kSeparatorSize = 1; 17 const int kSeparatorSize = 1;
17 18
18 // Default color of the separator.
19 const SkColor kDefaultColor = SkColorSetARGB(255, 233, 233, 233);
20
21 Separator::Separator(Orientation orientation) 19 Separator::Separator(Orientation orientation)
22 : orientation_(orientation), 20 : orientation_(orientation),
23 color_(kDefaultColor), 21 color_overridden_(false),
24 size_(kSeparatorSize) { 22 size_(kSeparatorSize) {
23 SetColorFromNativeTheme();
25 } 24 }
26 25
27 Separator::~Separator() { 26 Separator::~Separator() {
28 } 27 }
29 28
30 void Separator::SetColor(SkColor color) { 29 void Separator::SetColor(SkColor color) {
31 color_ = color; 30 color_ = color;
31 color_overridden_ = true;
32 SchedulePaint(); 32 SchedulePaint();
33 } 33 }
34 34
35 void Separator::SetPreferredSize(int size) { 35 void Separator::SetPreferredSize(int size) {
36 if (size != size_) { 36 if (size != size_) {
37 size_ = size; 37 size_ = size;
38 PreferredSizeChanged(); 38 PreferredSizeChanged();
39 } 39 }
40 } 40 }
41 41
42 void Separator::SetColorFromNativeTheme() {
43 color_ = GetNativeTheme()->GetSystemColor(
44 ui::NativeTheme::kColorId_SeparatorColor);
45 }
46
42 //////////////////////////////////////////////////////////////////////////////// 47 ////////////////////////////////////////////////////////////////////////////////
43 // Separator, View overrides: 48 // Separator, View overrides:
44 49
45 gfx::Size Separator::GetPreferredSize() const { 50 gfx::Size Separator::GetPreferredSize() const {
46 gfx::Size size = 51 gfx::Size size =
47 orientation_ == HORIZONTAL ? gfx::Size(1, size_) : gfx::Size(size_, 1); 52 orientation_ == HORIZONTAL ? gfx::Size(1, size_) : gfx::Size(size_, 1);
48 gfx::Insets insets = GetInsets(); 53 gfx::Insets insets = GetInsets();
49 size.Enlarge(insets.width(), insets.height()); 54 size.Enlarge(insets.width(), insets.height());
50 return size; 55 return size;
51 } 56 }
52 57
53 void Separator::GetAccessibleNodeData(ui::AXNodeData* node_data) { 58 void Separator::GetAccessibleNodeData(ui::AXNodeData* node_data) {
54 node_data->role = ui::AX_ROLE_SPLITTER; 59 node_data->role = ui::AX_ROLE_SPLITTER;
55 } 60 }
56 61
57 void Separator::OnPaint(gfx::Canvas* canvas) { 62 void Separator::OnPaint(gfx::Canvas* canvas) {
58 canvas->FillRect(GetContentsBounds(), color_); 63 canvas->FillRect(GetContentsBounds(), color_);
59 } 64 }
60 65
66 void Separator::OnNativeThemeChanged(const ui::NativeTheme* theme) {
67 if (!color_overridden_)
68 SetColorFromNativeTheme();
69 }
70
61 const char* Separator::GetClassName() const { 71 const char* Separator::GetClassName() const {
62 return kViewClassName; 72 return kViewClassName;
63 } 73 }
64 74
65 } // namespace views 75 } // 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