Home | History | Annotate | Download | only in views
      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 // 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 #pragma once
     13 
     14 #include <windows.h>
     15 
     16 #include "views/controls/textfield/textfield_controller.h"
     17 #include "views/window/dialog_delegate.h"
     18 
     19 namespace views {
     20 class Label;
     21 class ImageView;
     22 class Window;
     23 }
     24 
     25 class EditSearchEngineController;
     26 class EditSearchEngineControllerDelegate;
     27 class Profile;
     28 class TemplateURL;
     29 class TemplateURLModel;
     30 
     31 class EditSearchEngineDialog : public views::View,
     32                                public views::TextfieldController,
     33                                public views::DialogDelegate {
     34  public:
     35   // The |template_url| and/or |delegate| may be NULL.
     36   EditSearchEngineDialog(const TemplateURL* template_url,
     37                          EditSearchEngineControllerDelegate* delegate,
     38                          Profile* profile);
     39   virtual ~EditSearchEngineDialog() {}
     40 
     41   // Shows the dialog to the user.
     42   static void Show(gfx::NativeWindow parent,
     43                    const TemplateURL* template_url,
     44                    EditSearchEngineControllerDelegate* delegate,
     45                    Profile* profile);
     46 
     47   // views::DialogDelegate:
     48   virtual bool IsModal() const;
     49   virtual std::wstring GetWindowTitle() const;
     50   virtual bool IsDialogButtonEnabled(
     51       MessageBoxFlags::DialogButton button) const;
     52   virtual bool Cancel();
     53   virtual bool Accept();
     54   virtual views::View* GetContentsView();
     55 
     56   // views::TextfieldController:
     57   // Updates whether the user can accept the dialog as well as updating image
     58   // views showing whether value is valid.
     59   virtual void ContentsChanged(views::Textfield* sender,
     60                                const std::wstring& new_contents);
     61   virtual bool HandleKeyEvent(views::Textfield* sender,
     62                               const views::KeyEvent& key_event);
     63 
     64  private:
     65   void Init();
     66 
     67   // Create a Label containing the text with the specified message id.
     68   views::Label* CreateLabel(int message_id);
     69 
     70   // Creates a text field with the specified text. If |lowercase| is true, the
     71   // Textfield is configured to map all input to lower case.
     72   views::Textfield* CreateTextfield(const std::wstring& text, bool lowercase);
     73 
     74   // Invokes UpdateImageView for each of the images views.
     75   void UpdateImageViews();
     76 
     77   // Updates the tooltip and image of the image view based on is_valid. If
     78   // is_valid is false the tooltip of the image view is set to the message with
     79   // id invalid_message_id, otherwise the tooltip is set to the empty text.
     80   void UpdateImageView(views::ImageView* image_view,
     81                        bool is_valid,
     82                        int invalid_message_id);
     83 
     84   // Used to parent window to. May be NULL or an invalid window.
     85   HWND parent_;
     86 
     87   // View containing the buttons, text fields ...
     88   views::View* view_;
     89 
     90   // Text fields.
     91   views::Textfield* title_tf_;
     92   views::Textfield* keyword_tf_;
     93   views::Textfield* url_tf_;
     94 
     95   // Shows error images.
     96   views::ImageView* title_iv_;
     97   views::ImageView* keyword_iv_;
     98   views::ImageView* url_iv_;
     99 
    100   scoped_ptr<EditSearchEngineController> controller_;
    101 
    102   DISALLOW_COPY_AND_ASSIGN(EditSearchEngineDialog);
    103 };
    104 
    105 #endif  // CHROME_BROWSER_UI_VIEWS_EDIT_SEARCH_ENGINE_DIALOG_H_
    106