edit_search_engine_dialog.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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
3// found in the LICENSE file.
4
5// EditSearchEngineDialog provides text fields for editing a keyword: the title,
6// url and actual keyword. It is used by the KeywordEditorView of the Options
7// dialog, and also on its own to confirm the addition of a keyword added by
8// the ExternalJSObject via the RenderView.
9
10#ifndef CHROME_BROWSER_UI_VIEWS_EDIT_SEARCH_ENGINE_DIALOG_H_
11#define CHROME_BROWSER_UI_VIEWS_EDIT_SEARCH_ENGINE_DIALOG_H_
12
13#include "ui/views/controls/textfield/textfield_controller.h"
14#include "ui/views/window/dialog_delegate.h"
15
16namespace views {
17class Label;
18class ImageView;
19}
20
21class EditSearchEngineController;
22class EditSearchEngineControllerDelegate;
23class Profile;
24class TemplateURL;
25
26class EditSearchEngineDialog : public views::TextfieldController,
27                               public views::DialogDelegateView {
28 public:
29  // The |template_url| and/or |delegate| may be NULL.
30  EditSearchEngineDialog(TemplateURL* template_url,
31                         EditSearchEngineControllerDelegate* delegate,
32                         Profile* profile);
33  virtual ~EditSearchEngineDialog();
34
35  // Shows the dialog to the user.
36  static void Show(gfx::NativeWindow parent,
37                   TemplateURL* template_url,
38                   EditSearchEngineControllerDelegate* delegate,
39                   Profile* profile);
40
41  // views::DialogDelegate:
42  virtual ui::ModalType GetModalType() const OVERRIDE;
43  virtual base::string16 GetWindowTitle() const OVERRIDE;
44  virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
45  virtual bool Cancel() OVERRIDE;
46  virtual bool Accept() OVERRIDE;
47
48  // views::TextfieldController:
49  // Updates whether the user can accept the dialog as well as updating image
50  // views showing whether value is valid.
51  virtual void ContentsChanged(views::Textfield* sender,
52                               const base::string16& new_contents) OVERRIDE;
53  virtual bool HandleKeyEvent(views::Textfield* sender,
54                              const ui::KeyEvent& key_event) OVERRIDE;
55 private:
56  void Init();
57
58  // Create a Label containing the text with the specified message id.
59  views::Label* CreateLabel(int message_id);
60
61  // Creates a text field with the specified text. If |lowercase| is true, the
62  // Textfield is configured to map all input to lower case.
63  views::Textfield* CreateTextfield(const base::string16& text, bool lowercase);
64
65  // Invokes UpdateImageView for each of the images views.
66  void UpdateImageViews();
67
68  // Updates the tooltip and image of the image view based on is_valid. If
69  // is_valid is false the tooltip of the image view is set to the message with
70  // id invalid_message_id, otherwise the tooltip is set to the empty text.
71  void UpdateImageView(views::ImageView* image_view,
72                       bool is_valid,
73                       int invalid_message_id);
74
75  // View containing the buttons, text fields ...
76  views::View* view_;
77
78  // Text fields.
79  views::Textfield* title_tf_;
80  views::Textfield* keyword_tf_;
81  views::Textfield* url_tf_;
82
83  // Shows error images.
84  views::ImageView* title_iv_;
85  views::ImageView* keyword_iv_;
86  views::ImageView* url_iv_;
87
88  scoped_ptr<EditSearchEngineController> controller_;
89
90  DISALLOW_COPY_AND_ASSIGN(EditSearchEngineDialog);
91};
92
93#endif  // CHROME_BROWSER_UI_VIEWS_EDIT_SEARCH_ENGINE_DIALOG_H_
94