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