| 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/button/custom_button.h" | 5 #include "ui/views/controls/button/custom_button.h" |
| 6 | 6 |
| 7 #include "ui/accessibility/ax_view_state.h" | 7 #include "ui/accessibility/ax_view_state.h" |
| 8 #include "ui/base/material_design/material_design_controller.h" | 8 #include "ui/base/material_design/material_design_controller.h" |
| 9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 10 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 class MdFocusRing : public views::View { | 46 class MdFocusRing : public views::View { |
| 47 public: | 47 public: |
| 48 MdFocusRing() { | 48 MdFocusRing() { |
| 49 SetPaintToLayer(true); | 49 SetPaintToLayer(true); |
| 50 layer()->SetFillsBoundsOpaquely(false); | 50 layer()->SetFillsBoundsOpaquely(false); |
| 51 } | 51 } |
| 52 ~MdFocusRing() override {} | 52 ~MdFocusRing() override {} |
| 53 | 53 |
| 54 void OnPaint(gfx::Canvas* canvas) override { | 54 void OnPaint(gfx::Canvas* canvas) override { |
| 55 SkPaint paint; | 55 CustomButton::PaintMdFocusRing(canvas, this); |
| 56 paint.setAntiAlias(true); | |
| 57 paint.setColor(GetNativeTheme()->GetSystemColor( | |
| 58 ui::NativeTheme::kColorId_CallToActionColor)); | |
| 59 paint.setStyle(SkPaint::kStroke_Style); | |
| 60 paint.setStrokeWidth(1); | |
| 61 gfx::RectF rect(GetLocalBounds()); | |
| 62 rect.Inset(gfx::InsetsF(0.5)); | |
| 63 canvas->DrawRoundRect(rect, kFocusBorderCornerRadius, paint); | |
| 64 } | 56 } |
| 65 | 57 |
| 66 private: | 58 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(MdFocusRing); | 59 DISALLOW_COPY_AND_ASSIGN(MdFocusRing); |
| 68 }; | 60 }; |
| 69 | 61 |
| 70 } // namespace | 62 } // namespace |
| 71 | 63 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////////// |
| 73 // CustomButton, public: | 65 // CustomButton, public: |
| 74 | 66 |
| 75 // static | 67 // static |
| 76 const char CustomButton::kViewClassName[] = "CustomButton"; | 68 const char CustomButton::kViewClassName[] = "CustomButton"; |
| 77 | 69 |
| 78 // static | 70 // static |
| 79 const CustomButton* CustomButton::AsCustomButton(const views::View* view) { | 71 const CustomButton* CustomButton::AsCustomButton(const views::View* view) { |
| 80 return AsCustomButton(const_cast<views::View*>(view)); | 72 return AsCustomButton(const_cast<View*>(view)); |
| 81 } | 73 } |
| 82 | 74 |
| 75 // static |
| 83 CustomButton* CustomButton::AsCustomButton(views::View* view) { | 76 CustomButton* CustomButton::AsCustomButton(views::View* view) { |
| 84 if (view) { | 77 if (view) { |
| 85 const char* classname = view->GetClassName(); | 78 const char* classname = view->GetClassName(); |
| 86 if (!strcmp(classname, Checkbox::kViewClassName) || | 79 if (!strcmp(classname, Checkbox::kViewClassName) || |
| 87 !strcmp(classname, CustomButton::kViewClassName) || | 80 !strcmp(classname, CustomButton::kViewClassName) || |
| 88 !strcmp(classname, ImageButton::kViewClassName) || | 81 !strcmp(classname, ImageButton::kViewClassName) || |
| 89 !strcmp(classname, LabelButton::kViewClassName) || | 82 !strcmp(classname, LabelButton::kViewClassName) || |
| 90 !strcmp(classname, RadioButton::kViewClassName) || | 83 !strcmp(classname, RadioButton::kViewClassName) || |
| 91 !strcmp(classname, MenuButton::kViewClassName)) { | 84 !strcmp(classname, MenuButton::kViewClassName)) { |
| 92 return static_cast<CustomButton*>(view); | 85 return static_cast<CustomButton*>(view); |
| 93 } | 86 } |
| 94 } | 87 } |
| 95 return NULL; | 88 return NULL; |
| 96 } | 89 } |
| 97 | 90 |
| 91 // static |
| 92 void CustomButton::PaintMdFocusRing(gfx::Canvas* canvas, views::View* view) { |
| 93 SkPaint paint; |
| 94 paint.setAntiAlias(true); |
| 95 paint.setColor(view->GetNativeTheme()->GetSystemColor( |
| 96 ui::NativeTheme::kColorId_CallToActionColor)); |
| 97 paint.setStyle(SkPaint::kStroke_Style); |
| 98 paint.setStrokeWidth(1); |
| 99 gfx::RectF rect(view->GetLocalBounds()); |
| 100 rect.Inset(gfx::InsetsF(0.5)); |
| 101 canvas->DrawRoundRect(rect, kFocusBorderCornerRadius, paint); |
| 102 } |
| 103 |
| 98 CustomButton::~CustomButton() {} | 104 CustomButton::~CustomButton() {} |
| 99 | 105 |
| 100 void CustomButton::SetState(ButtonState state) { | 106 void CustomButton::SetState(ButtonState state) { |
| 101 if (state == state_) | 107 if (state == state_) |
| 102 return; | 108 return; |
| 103 | 109 |
| 104 if (animate_on_state_change_ && | 110 if (animate_on_state_change_ && |
| 105 (!is_throbbing_ || !hover_animation_.is_animating())) { | 111 (!is_throbbing_ || !hover_animation_.is_animating())) { |
| 106 is_throbbing_ = false; | 112 is_throbbing_ = false; |
| 107 if ((state_ == STATE_HOVERED) && (state == STATE_NORMAL)) { | 113 if ((state_ == STATE_HOVERED) && (state == STATE_NORMAL)) { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 Button::NotifyClick(event); | 504 Button::NotifyClick(event); |
| 499 } | 505 } |
| 500 | 506 |
| 501 void CustomButton::OnClickCanceled(const ui::Event& event) { | 507 void CustomButton::OnClickCanceled(const ui::Event& event) { |
| 502 if (ink_drop_delegate()) | 508 if (ink_drop_delegate()) |
| 503 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); | 509 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); |
| 504 Button::OnClickCanceled(event); | 510 Button::OnClickCanceled(event); |
| 505 } | 511 } |
| 506 | 512 |
| 507 } // namespace views | 513 } // namespace views |
| OLD | NEW |