summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/translate_infobars.h
blob: 4bd752fe21cde3bf6598924cff46bad1e752ec7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_GTK_TRANSLATE_INFOBARS_H_
#define CHROME_BROWSER_GTK_TRANSLATE_INFOBARS_H_

#include <gtk/gtk.h>

#include "app/gtk_signal.h"
#include "app/menus/simple_menu_model.h"
#include "chrome/browser/gtk/infobar_gtk.h"
#include "chrome/browser/gtk/menu_gtk.h"
#include "chrome/browser/translate/translate_infobars_delegates.h"
#include "chrome/common/notification_registrar.h"

class OptionsMenuModel;

// InfoBar that asks user if they want to translate a page that isn't in the
// user's language to their language. Bar changes during and after translation.
class TranslateInfoBar : public InfoBar,
                         public menus::SimpleMenuModel::Delegate,
                         public MenuGtk::Delegate {
 public:
  explicit TranslateInfoBar(TranslateInfoBarDelegate* delegate);
  virtual ~TranslateInfoBar();

  // Overridden from NotificationObserver (through InfoBar):
  virtual void Observe(NotificationType type,
      const NotificationSource& source, const NotificationDetails& details);

  // Overridden for both menus::SimpleMenuModel::Delegate and MenuGtk::Delegate:
  virtual bool IsCommandIdChecked(int command_id) const;
  virtual bool IsCommandIdEnabled(int command_id) const;

  // Overridden from menus::SimpleMenuModel::Delegate:
  virtual bool GetAcceleratorForCommandId(int command_id,
      menus::Accelerator* accelerator);
  virtual void ExecuteCommand(int command_id);

  // Overridden from MenuGtk::Delegate:
  virtual void ExecuteCommandById(int command_id) {
    ExecuteCommand(command_id);
  }

 private:
  // Builds all the widgets and sets the initial view of the dialog.
  void BuildWidgets();

  // Changes the layout of the info bar, displaying the correct widgets in the
  // correct order for |new_state|.
  void UpdateState(TranslateInfoBarDelegate::TranslateState new_state);

  // Sets the text in the three labels for the current state.
  void SetLabels();

  // Casts delegate() to the only possible subclass.
  TranslateInfoBarDelegate* GetDelegate() const;

  // Called after OnOriginalModified or OnTargetModified.
  void LanguageModified();

  CHROMEGTK_CALLBACK_0(TranslateInfoBar, void, OnOriginalModified);
  CHROMEGTK_CALLBACK_0(TranslateInfoBar, void, OnTargetModified);
  CHROMEGTK_CALLBACK_0(TranslateInfoBar, void, OnAcceptPressed);
  CHROMEGTK_CALLBACK_0(TranslateInfoBar, void, OnDenyPressed);
  CHROMEGTK_CALLBACK_0(TranslateInfoBar, void, OnOptionsClicked);

  GtkWidget* translate_box_;
  GtkWidget* label_1_;
  GtkWidget* label_2_;
  GtkWidget* label_3_;
  GtkWidget* translating_label_;

  GtkWidget* accept_button_;
  GtkWidget* accept_button_vbox_;

  GtkWidget* deny_button_;
  GtkWidget* deny_button_vbox_;

  GtkWidget* original_language_combobox_;
  GtkWidget* original_language_combobox_vbox_;

  GtkWidget* target_language_combobox_;
  GtkWidget* target_language_combobox_vbox_;

  GtkWidget* options_menu_button_;
  scoped_ptr<MenuGtk> options_menu_menu_;
  scoped_ptr<OptionsMenuModel> options_menu_model_;

  // This is true if language placeholders in label have been swapped.
  bool swapped_language_placeholders_;

  NotificationRegistrar notification_registrar_;

  DISALLOW_COPY_AND_ASSIGN(TranslateInfoBar);
};

#endif  // CHROME_BROWSER_GTK_TRANSLATE_INFOBARS_H_