translate_infobar_base.h revision 3f50c38dc070f4bb515c1b64450dae14f316474e
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_VIEWS_INFOBARS_TRANSLATE_INFOBAR_BASE_H_
6#define CHROME_BROWSER_UI_VIEWS_INFOBARS_TRANSLATE_INFOBAR_BASE_H_
7#pragma once
8
9#include "chrome/browser/translate/translate_infobar_view.h"
10#include "chrome/browser/views/infobars/infobars.h"
11
12class TranslateInfoBarDelegate;
13
14namespace views {
15class MenuButton;
16class ViewMenuDelegate;
17}
18
19// This class contains some of the base functionality that translate infobars
20// use.
21class TranslateInfoBarBase : public TranslateInfoBarView,
22                             public InfoBar {
23 public:
24  explicit TranslateInfoBarBase(TranslateInfoBarDelegate* delegate);
25  virtual ~TranslateInfoBarBase();
26
27  // TranslateInfoBarView implementation:
28  virtual void OriginalLanguageChanged() {}
29  virtual void TargetLanguageChanged() {}
30
31  // Overridden from views::View:
32  virtual void Layout();
33  virtual void PaintBackground(gfx::Canvas* canvas);
34
35 protected:
36  // Overridden from ui::AnimationDelegate:
37  virtual void AnimationProgressed(const ui::Animation* animation);
38
39  // Creates a label with the appropriate font and color for the translate
40  // infobars.
41  views::Label* CreateLabel(const string16& text);
42
43  // Creates a menu-button with a custom appearance for the translate infobars.
44  views::MenuButton* CreateMenuButton(const string16& text,
45                                      bool normal_has_border,
46                                      views::ViewMenuDelegate* menu_delegate);
47
48  // Returns the location at which the menu triggered by |menu_button| should be
49  // positioned.
50  gfx::Point DetermineMenuPosition(views::MenuButton* menu_button);
51
52  // Convenience to retrieve the TranslateInfoBarDelegate for this infobar.
53  TranslateInfoBarDelegate* GetDelegate() const;
54
55  // The translate icon.
56  views::ImageView* icon_;
57
58  InfoBarBackground normal_background_;
59  InfoBarBackground error_background_;
60  scoped_ptr<ui::SlideAnimation> background_color_animation_;
61
62 private:
63  // Returns the background that should be displayed when not animating.
64  const InfoBarBackground& GetBackground() const;
65
66  // Paints |background| to |canvas| with the opacity level based on
67  // |animation_value|.
68  void FadeBackground(gfx::Canvas* canvas,
69                      double animation_value,
70                      const InfoBarBackground& background);
71
72  DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarBase);
73};
74
75#endif  // CHROME_BROWSER_UI_VIEWS_INFOBARS_TRANSLATE_INFOBAR_BASE_H_
76