OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" | 5 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
6 | 6 |
7 #if defined(TOOLKIT_USES_GTK) | 7 #if defined(TOOLKIT_USES_GTK) |
8 #include <gdk/gdk.h> | 8 #include <gdk/gdk.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <set> | 12 #include <set> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "chrome/browser/content_settings/host_content_settings_map.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 19 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
20 #include "chrome/browser/ui/views/browser_dialogs.h" | 20 #include "chrome/browser/ui/views/browser_dialogs.h" |
21 #include "chrome/browser/ui/views/bubble/bubble.h" | |
22 #include "content/browser/plugin_service.h" | 21 #include "content/browser/plugin_service.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
25 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
26 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
27 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/views/layout/grid_layout.h" | 27 #include "ui/views/layout/grid_layout.h" |
29 #include "ui/views/layout/layout_constants.h" | 28 #include "ui/views/layout/layout_constants.h" |
30 #include "views/controls/button/radio_button.h" | 29 #include "views/controls/button/radio_button.h" |
31 #include "views/controls/button/text_button.h" | 30 #include "views/controls/button/text_button.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); | 99 static HCURSOR g_hand_cursor = LoadCursor(NULL, IDC_HAND); |
101 return g_hand_cursor; | 100 return g_hand_cursor; |
102 #elif defined(TOOLKIT_USES_GTK) | 101 #elif defined(TOOLKIT_USES_GTK) |
103 return gfx::GetCursor(GDK_HAND2); | 102 return gfx::GetCursor(GDK_HAND2); |
104 #endif | 103 #endif |
105 } | 104 } |
106 | 105 |
107 ContentSettingBubbleContents::ContentSettingBubbleContents( | 106 ContentSettingBubbleContents::ContentSettingBubbleContents( |
108 ContentSettingBubbleModel* content_setting_bubble_model, | 107 ContentSettingBubbleModel* content_setting_bubble_model, |
109 Profile* profile, | 108 Profile* profile, |
110 TabContents* tab_contents) | 109 TabContents* tab_contents, |
111 : content_setting_bubble_model_(content_setting_bubble_model), | 110 views::View* anchor_view, |
| 111 views::BubbleBorder::ArrowLocation arrow_location) |
| 112 : BubbleDelegateView(anchor_view, arrow_location, SK_ColorWHITE), |
| 113 content_setting_bubble_model_(content_setting_bubble_model), |
112 profile_(profile), | 114 profile_(profile), |
113 tab_contents_(tab_contents), | 115 tab_contents_(tab_contents), |
114 bubble_(NULL), | |
115 custom_link_(NULL), | 116 custom_link_(NULL), |
116 manage_link_(NULL), | 117 manage_link_(NULL), |
117 close_button_(NULL) { | 118 close_button_(NULL) { |
118 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, | 119 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, |
119 content::Source<TabContents>(tab_contents)); | 120 content::Source<TabContents>(tab_contents)); |
120 } | 121 } |
121 | 122 |
122 ContentSettingBubbleContents::~ContentSettingBubbleContents() { | 123 ContentSettingBubbleContents::~ContentSettingBubbleContents() { |
123 } | 124 } |
124 | 125 |
125 gfx::Size ContentSettingBubbleContents::GetPreferredSize() { | 126 gfx::Size ContentSettingBubbleContents::GetPreferredSize() { |
126 gfx::Size preferred_size(views::View::GetPreferredSize()); | 127 gfx::Size preferred_size(views::View::GetPreferredSize()); |
127 int preferred_width = | 128 int preferred_width = |
128 (!content_setting_bubble_model_->bubble_content().domain_lists.empty() && | 129 (!content_setting_bubble_model_->bubble_content().domain_lists.empty() && |
129 (kMinMultiLineContentsWidth > preferred_size.width())) ? | 130 (kMinMultiLineContentsWidth > preferred_size.width())) ? |
130 kMinMultiLineContentsWidth : preferred_size.width(); | 131 kMinMultiLineContentsWidth : preferred_size.width(); |
131 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth)); | 132 preferred_size.set_width(std::min(preferred_width, kMaxContentsWidth)); |
132 return preferred_size; | 133 return preferred_size; |
133 } | 134 } |
134 | 135 |
135 void ContentSettingBubbleContents::ViewHierarchyChanged(bool is_add, | 136 gfx::Point ContentSettingBubbleContents::GetAnchorPoint() { |
136 View* parent, | 137 return BubbleDelegateView::GetAnchorPoint().Subtract(gfx::Point(0, 5)); |
137 View* child) { | |
138 if (is_add && (child == this)) | |
139 InitControlLayout(); | |
140 } | 138 } |
141 | 139 |
142 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, | 140 void ContentSettingBubbleContents::Init() { |
143 const views::Event& event) { | |
144 if (sender == close_button_) { | |
145 bubble_->set_fade_away_on_close(true); | |
146 bubble_->Close(); // CAREFUL: This deletes us. | |
147 return; | |
148 } | |
149 | |
150 for (RadioGroup::const_iterator i = radio_group_.begin(); | |
151 i != radio_group_.end(); ++i) { | |
152 if (sender == *i) { | |
153 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); | |
154 return; | |
155 } | |
156 } | |
157 NOTREACHED() << "unknown radio"; | |
158 } | |
159 | |
160 void ContentSettingBubbleContents::LinkClicked(views::Link* source, | |
161 int event_flags) { | |
162 if (source == custom_link_) { | |
163 content_setting_bubble_model_->OnCustomLinkClicked(); | |
164 bubble_->set_fade_away_on_close(true); | |
165 bubble_->Close(); // CAREFUL: This deletes us. | |
166 return; | |
167 } | |
168 if (source == manage_link_) { | |
169 bubble_->set_fade_away_on_close(true); | |
170 content_setting_bubble_model_->OnManageLinkClicked(); | |
171 // CAREFUL: Showing the settings window activates it, which deactivates the | |
172 // info bubble, which causes it to close, which deletes us. | |
173 return; | |
174 } | |
175 | |
176 PopupLinks::const_iterator i(popup_links_.find(source)); | |
177 DCHECK(i != popup_links_.end()); | |
178 content_setting_bubble_model_->OnPopupClicked(i->second); | |
179 } | |
180 | |
181 void ContentSettingBubbleContents::Observe( | |
182 int type, | |
183 const content::NotificationSource& source, | |
184 const content::NotificationDetails& details) { | |
185 DCHECK(type == content::NOTIFICATION_TAB_CONTENTS_DESTROYED); | |
186 DCHECK(source == content::Source<TabContents>(tab_contents_)); | |
187 tab_contents_ = NULL; | |
188 } | |
189 | |
190 void ContentSettingBubbleContents::InitControlLayout() { | |
191 using views::GridLayout; | 141 using views::GridLayout; |
192 | 142 |
193 GridLayout* layout = new views::GridLayout(this); | 143 GridLayout* layout = new views::GridLayout(this); |
194 SetLayoutManager(layout); | 144 SetLayoutManager(layout); |
195 | 145 |
196 const int single_column_set_id = 0; | 146 const int single_column_set_id = 0; |
197 views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id); | 147 views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id); |
198 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, | 148 column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1, |
199 GridLayout::USE_PREF, 0, 0); | 149 GridLayout::USE_PREF, 0, 0); |
200 | 150 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 283 |
334 layout->StartRow(0, double_column_set_id); | 284 layout->StartRow(0, double_column_set_id); |
335 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); | 285 manage_link_ = new views::Link(UTF8ToUTF16(bubble_content.manage_link)); |
336 manage_link_->set_listener(this); | 286 manage_link_->set_listener(this); |
337 layout->AddView(manage_link_); | 287 layout->AddView(manage_link_); |
338 | 288 |
339 close_button_ = new views::NativeTextButton( | 289 close_button_ = new views::NativeTextButton( |
340 this, l10n_util::GetStringUTF16(IDS_DONE)); | 290 this, l10n_util::GetStringUTF16(IDS_DONE)); |
341 layout->AddView(close_button_); | 291 layout->AddView(close_button_); |
342 } | 292 } |
| 293 |
| 294 void ContentSettingBubbleContents::ButtonPressed(views::Button* sender, |
| 295 const views::Event& event) { |
| 296 if (sender == close_button_) { |
| 297 StartFade(false); |
| 298 return; |
| 299 } |
| 300 |
| 301 for (RadioGroup::const_iterator i = radio_group_.begin(); |
| 302 i != radio_group_.end(); ++i) { |
| 303 if (sender == *i) { |
| 304 content_setting_bubble_model_->OnRadioClicked(i - radio_group_.begin()); |
| 305 return; |
| 306 } |
| 307 } |
| 308 NOTREACHED() << "unknown radio"; |
| 309 } |
| 310 |
| 311 void ContentSettingBubbleContents::LinkClicked(views::Link* source, |
| 312 int event_flags) { |
| 313 if (source == custom_link_) { |
| 314 content_setting_bubble_model_->OnCustomLinkClicked(); |
| 315 StartFade(false); |
| 316 return; |
| 317 } |
| 318 if (source == manage_link_) { |
| 319 StartFade(false); |
| 320 content_setting_bubble_model_->OnManageLinkClicked(); |
| 321 // CAREFUL: Showing the settings window activates it, which deactivates the |
| 322 // info bubble, which causes it to close, which deletes us. |
| 323 return; |
| 324 } |
| 325 |
| 326 PopupLinks::const_iterator i(popup_links_.find(source)); |
| 327 DCHECK(i != popup_links_.end()); |
| 328 content_setting_bubble_model_->OnPopupClicked(i->second); |
| 329 } |
| 330 |
| 331 void ContentSettingBubbleContents::Observe( |
| 332 int type, |
| 333 const content::NotificationSource& source, |
| 334 const content::NotificationDetails& details) { |
| 335 DCHECK(type == content::NOTIFICATION_TAB_CONTENTS_DESTROYED); |
| 336 DCHECK(source == content::Source<TabContents>(tab_contents_)); |
| 337 tab_contents_ = NULL; |
| 338 } |
OLD | NEW |