| 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/text_button.h" | 5 #include "ui/views/controls/button/text_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 111 } |
| 112 | 112 |
| 113 //////////////////////////////////////////////////////////////////////////////// | 113 //////////////////////////////////////////////////////////////////////////////// |
| 114 // | 114 // |
| 115 // TextButtonDefaultBorder - painting | 115 // TextButtonDefaultBorder - painting |
| 116 // | 116 // |
| 117 //////////////////////////////////////////////////////////////////////////////// | 117 //////////////////////////////////////////////////////////////////////////////// |
| 118 void TextButtonDefaultBorder::Paint(const View& view, gfx::Canvas* canvas) { | 118 void TextButtonDefaultBorder::Paint(const View& view, gfx::Canvas* canvas) { |
| 119 const TextButton* button = static_cast<const TextButton*>(&view); | 119 const TextButton* button = static_cast<const TextButton*>(&view); |
| 120 int state = button->state(); | 120 int state = button->state(); |
| 121 bool animating = button->GetAnimation()->is_animating(); |
| 121 | 122 |
| 122 Painter* painter = normal_painter_.get(); | 123 Painter* painter = normal_painter_.get(); |
| 124 // Use the hot painter when we're hovered. Also use the hot painter when we're |
| 125 // STATE_NORMAL and |animating| so that we show throb animations started from |
| 126 // CustomButton::StartThrobbing which should start throbbing the button |
| 127 // regardless of whether it is hovered. |
| 123 if (button->show_multiple_icon_states() && | 128 if (button->show_multiple_icon_states() && |
| 124 ((state == TextButton::STATE_HOVERED) || | 129 ((state == TextButton::STATE_HOVERED) || |
| 125 (state == TextButton::STATE_PRESSED))) { | 130 (state == TextButton::STATE_PRESSED) || |
| 126 painter = (state == TextButton::STATE_HOVERED) ? | 131 ((state == TextButton::STATE_NORMAL) && animating))) { |
| 127 hot_painter_.get() : pushed_painter_.get(); | 132 painter = (state == TextButton::STATE_PRESSED) ? |
| 133 pushed_painter_.get() : hot_painter_.get(); |
| 128 } | 134 } |
| 129 if (painter) { | 135 if (painter) { |
| 130 if (button->GetAnimation()->is_animating()) { | 136 if (animating) { |
| 131 // TODO(pkasting): Really this should crossfade between states so it could | 137 // TODO(pkasting): Really this should crossfade between states so it could |
| 132 // handle the case of having a non-NULL |normal_set_|. | 138 // handle the case of having a non-NULL |normal_painter_|. |
| 133 canvas->SaveLayerAlpha(static_cast<uint8>( | 139 canvas->SaveLayerAlpha(static_cast<uint8>( |
| 134 button->GetAnimation()->CurrentValueBetween(0, 255))); | 140 button->GetAnimation()->CurrentValueBetween(0, 255))); |
| 135 painter->Paint(canvas, view.size()); | 141 painter->Paint(canvas, view.size()); |
| 136 canvas->Restore(); | 142 canvas->Restore(); |
| 137 } else { | 143 } else { |
| 138 painter->Paint(canvas, view.size()); | 144 painter->Paint(canvas, view.size()); |
| 139 } | 145 } |
| 140 } | 146 } |
| 141 } | 147 } |
| 142 | 148 |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 if (show_multiple_icon_states_) { | 735 if (show_multiple_icon_states_) { |
| 730 if (has_hover_icon_ && (state() == STATE_HOVERED)) | 736 if (has_hover_icon_ && (state() == STATE_HOVERED)) |
| 731 return icon_hover_; | 737 return icon_hover_; |
| 732 if (has_pushed_icon_ && (state() == STATE_PRESSED)) | 738 if (has_pushed_icon_ && (state() == STATE_PRESSED)) |
| 733 return icon_pushed_; | 739 return icon_pushed_; |
| 734 } | 740 } |
| 735 return icon_; | 741 return icon_; |
| 736 } | 742 } |
| 737 | 743 |
| 738 } // namespace views | 744 } // namespace views |
| OLD | NEW |