OLD | NEW |
| (Empty) |
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_VIEWS_OPTIONS_EXCEPTION_EDITOR_VIEW_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTION_EDITOR_VIEW_H_ | |
7 #pragma once | |
8 | |
9 #include <string> | |
10 | |
11 #include "chrome/browser/content_setting_combo_model.h" | |
12 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
13 #include "chrome/common/content_settings.h" | |
14 #include "chrome/common/content_settings_types.h" | |
15 #include "views/controls/button/checkbox.h" | |
16 #include "views/controls/combobox/combobox.h" | |
17 #include "views/controls/textfield/textfield_controller.h" | |
18 #include "views/window/dialog_delegate.h" | |
19 | |
20 namespace views { | |
21 class ImageView; | |
22 class Label; | |
23 } | |
24 | |
25 class ContentExceptionsTableModel; | |
26 | |
27 // ExceptionEditorView is responsible for showing a dialog that allows the user | |
28 // to create or edit a single content exception. If the user clicks ok the | |
29 // delegate is notified and completes the edit. | |
30 // | |
31 // To use an ExceptionEditorView create one and invoke Show on it. | |
32 // ExceptionEditorView is deleted when the dialog closes. | |
33 class ExceptionEditorView : public views::View, | |
34 public views::TextfieldController, | |
35 public views::DialogDelegate { | |
36 public: | |
37 class Delegate { | |
38 public: | |
39 // Invoked when the user accepts the edit. | |
40 virtual void AcceptExceptionEdit( | |
41 const ContentSettingsPattern& pattern, | |
42 ContentSetting setting, | |
43 bool is_off_the_record, | |
44 int index, | |
45 bool is_new) = 0; | |
46 | |
47 protected: | |
48 virtual ~Delegate() {} | |
49 }; | |
50 | |
51 // Creates a new ExceptionEditorView with the supplied args. |index| is the | |
52 // index into the ContentExceptionsTableModel of the exception. This is not | |
53 // used by ExceptionEditorView but instead passed to the delegate. | |
54 ExceptionEditorView(Delegate* delegate, | |
55 ContentExceptionsTableModel* model, | |
56 bool allow_off_the_record, | |
57 int index, | |
58 const ContentSettingsPattern& pattern, | |
59 ContentSetting setting, | |
60 bool is_off_the_record); | |
61 virtual ~ExceptionEditorView() {} | |
62 | |
63 void Show(gfx::NativeWindow parent); | |
64 | |
65 // views::DialogDelegate overrides. | |
66 virtual bool IsModal() const; | |
67 virtual std::wstring GetWindowTitle() const; | |
68 virtual bool IsDialogButtonEnabled( | |
69 MessageBoxFlags::DialogButton button) const; | |
70 virtual bool Cancel(); | |
71 virtual bool Accept(); | |
72 virtual views::View* GetContentsView(); | |
73 | |
74 // views::TextfieldController: | |
75 // Updates whether the user can accept the dialog as well as updating image | |
76 // views showing whether value is valid. | |
77 virtual void ContentsChanged(views::Textfield* sender, | |
78 const std::wstring& new_contents); | |
79 virtual bool HandleKeyEvent(views::Textfield* sender, | |
80 const views::KeyEvent& key_event); | |
81 | |
82 private: | |
83 void Init(); | |
84 | |
85 views::Label* CreateLabel(int message_id); | |
86 | |
87 // Returns true if we're adding a new item. | |
88 bool is_new() const { return index_ == -1; } | |
89 | |
90 bool IsPatternValid(const ContentSettingsPattern& pattern, | |
91 bool is_off_the_record) const; | |
92 | |
93 void UpdateImageView(views::ImageView* image_view, bool is_valid); | |
94 | |
95 Delegate* delegate_; | |
96 ContentExceptionsTableModel* model_; | |
97 ContentSettingComboModel cb_model_; | |
98 | |
99 // Index of the item being edited. If -1, indices this is a new entry. | |
100 const bool allow_off_the_record_; | |
101 const int index_; | |
102 const ContentSettingsPattern pattern_; | |
103 const ContentSetting setting_; | |
104 const bool is_off_the_record_; | |
105 | |
106 views::Textfield* pattern_tf_; | |
107 views::ImageView* pattern_iv_; | |
108 views::Combobox* action_cb_; | |
109 views::Checkbox* incognito_cb_; | |
110 | |
111 DISALLOW_COPY_AND_ASSIGN(ExceptionEditorView); | |
112 }; | |
113 | |
114 #endif // CHROME_BROWSER_UI_VIEWS_OPTIONS_EXCEPTION_EDITOR_VIEW_H_ | |
OLD | NEW |