Chromium Code Reviews| OLD | NEW |
|---|---|
| 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::SetColorFromNativeTheme() { | |
|
sky
2017/01/10 15:56:37
Style guide says declaration and definition order
Tom (Use chromium acct)
2017/01/10 20:59:10
Done.
| |
| 36 color_ = GetNativeTheme()->GetSystemColor( | |
| 37 ui::NativeTheme::kColorId_SeparatorColor); | |
| 38 } | |
| 39 | |
| 35 void Separator::SetPreferredSize(int size) { | 40 void Separator::SetPreferredSize(int size) { |
| 36 if (size != size_) { | 41 if (size != size_) { |
| 37 size_ = size; | 42 size_ = size; |
| 38 PreferredSizeChanged(); | 43 PreferredSizeChanged(); |
| 39 } | 44 } |
| 40 } | 45 } |
| 41 | 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 |
| OLD | NEW |