OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_UI_GTK_INFOBAR_ARROW_MODEL_H_ |
| 6 #define CHROME_BROWSER_UI_GTK_INFOBAR_ARROW_MODEL_H_ |
| 7 |
| 8 #include <gtk/gtk.h> |
| 9 |
| 10 #include "third_party/skia/include/core/SkPaint.h" |
| 11 #include "ui/base/animation/animation_delegate.h" |
| 12 #include "ui/base/animation/slide_animation.h" |
| 13 |
| 14 namespace gfx { |
| 15 class Point; |
| 16 } |
| 17 |
| 18 class InfoBar; |
| 19 |
| 20 // A helper class that tracks the state of an infobar arrow and provides a |
| 21 // utility to draw it. |
| 22 class InfoBarArrowModel : public ui::AnimationDelegate { |
| 23 public: |
| 24 class Observer { |
| 25 public: |
| 26 // The arrow has changed states; relevant widgets need to be repainted. |
| 27 virtual void PaintStateChanged() = 0; |
| 28 }; |
| 29 |
| 30 explicit InfoBarArrowModel(Observer* observer); |
| 31 virtual ~InfoBarArrowModel(); |
| 32 |
| 33 // An infobar has been added or removed that will affect the state of this |
| 34 // arrow. |
| 35 void ShowArrowFor(InfoBar* bar, bool animate); |
| 36 |
| 37 // Returns true if the arrow is showing at all. |
| 38 bool NeedToDrawInfoBarArrow(); |
| 39 |
| 40 // Paints the arrow on |widget|, in response to |expose|, with the bottom |
| 41 // center of the arrow at |origin|, drawing a border with |border_color|. |
| 42 void Paint(GtkWidget* widget, |
| 43 GdkEventExpose* expose, |
| 44 const gfx::Point& origin, |
| 45 const GdkColor& border_color); |
| 46 |
| 47 // Overridden from ui::AnimationDelegate. |
| 48 virtual void AnimationEnded(const ui::Animation* animation); |
| 49 virtual void AnimationProgressed(const ui::Animation* animation); |
| 50 virtual void AnimationCanceled(const ui::Animation* animation); |
| 51 |
| 52 private: |
| 53 // A pair of colors used to draw a gradient for an arrow. |
| 54 struct InfoBarColors { |
| 55 SkColor top; |
| 56 SkColor bottom; |
| 57 }; |
| 58 |
| 59 // Calculates the currently showing arrow color, which is a blend of the new |
| 60 // arrow color and the old arrow color. |
| 61 InfoBarColors CurrentInfoBarColors(); |
| 62 |
| 63 // The view that owns us. |
| 64 Observer* observer_; |
| 65 |
| 66 // An animation that tracks the progress of the transition from the last color |
| 67 // to the new color. |
| 68 ui::SlideAnimation animation_; |
| 69 |
| 70 // The color we are animating towards. |
| 71 InfoBarColors target_colors_; |
| 72 // The last color we showed (the one we are animating away from). |
| 73 InfoBarColors previous_colors_; |
| 74 |
| 75 DISALLOW_COPY_AND_ASSIGN(InfoBarArrowModel); |
| 76 }; |
| 77 |
| 78 #endif // CHROME_BROWSER_UI_GTK_INFOBAR_ARROW_MODEL_H_ |
OLD | NEW |