OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/toolbar_view.h" | 5 #include "chrome/browser/ui/views/toolbar_view.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
10 #include "chrome/browser/command_updater.h" | 10 #include "chrome/browser/command_updater.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
45 #include "grit/theme_resources.h" | 45 #include "grit/theme_resources.h" |
46 #include "ui/base/accessibility/accessible_view_state.h" | 46 #include "ui/base/accessibility/accessible_view_state.h" |
47 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
48 #include "ui/base/layout.h" | 48 #include "ui/base/layout.h" |
49 #include "ui/base/resource/resource_bundle.h" | 49 #include "ui/base/resource/resource_bundle.h" |
50 #include "ui/base/theme_provider.h" | 50 #include "ui/base/theme_provider.h" |
51 #include "ui/gfx/canvas.h" | 51 #include "ui/gfx/canvas.h" |
52 #include "ui/gfx/image/canvas_image_source.h" | 52 #include "ui/gfx/image/canvas_image_source.h" |
53 #include "ui/views/controls/button/button_dropdown.h" | 53 #include "ui/views/controls/button/button_dropdown.h" |
54 #include "ui/views/controls/label.h" | |
55 #include "ui/views/controls/link.h" | |
54 #include "ui/views/controls/menu/menu_listener.h" | 56 #include "ui/views/controls/menu/menu_listener.h" |
55 #include "ui/views/focus/view_storage.h" | 57 #include "ui/views/focus/view_storage.h" |
58 #include "ui/views/layout/grid_layout.h" | |
59 #include "ui/views/layout/layout_constants.h" | |
56 #include "ui/views/widget/tooltip_manager.h" | 60 #include "ui/views/widget/tooltip_manager.h" |
57 #include "ui/views/widget/widget.h" | 61 #include "ui/views/widget/widget.h" |
58 #include "ui/views/window/non_client_view.h" | 62 #include "ui/views/window/non_client_view.h" |
59 | 63 |
60 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
61 #include "chrome/browser/enumerate_modules_model_win.h" | 65 #include "chrome/browser/enumerate_modules_model_win.h" |
62 #include "chrome/browser/ui/views/critical_notification_bubble_view.h" | 66 #include "chrome/browser/ui/views/critical_notification_bubble_view.h" |
63 #if !defined(USE_AURA) | 67 #if !defined(USE_AURA) |
64 #include "chrome/browser/ui/views/app_menu_button_win.h" | 68 #include "chrome/browser/ui/views/app_menu_button_win.h" |
65 #endif | 69 #endif |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 kBadgeTopMargin); | 144 kBadgeTopMargin); |
141 } | 145 } |
142 | 146 |
143 private: | 147 private: |
144 const gfx::ImageSkia icon_; | 148 const gfx::ImageSkia icon_; |
145 const gfx::ImageSkia badge_; | 149 const gfx::ImageSkia badge_; |
146 | 150 |
147 DISALLOW_COPY_AND_ASSIGN(BadgeImageSource); | 151 DISALLOW_COPY_AND_ASSIGN(BadgeImageSource); |
148 }; | 152 }; |
149 | 153 |
154 class HomePageUndoBubble : public views::BubbleDelegateView, | |
155 public views::ButtonListener, | |
Peter Kasting
2013/01/17 23:48:42
Nit: All part declarations should be aligned
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
156 public views::LinkListener { | |
157 public: | |
158 // |browser| is the opening browser and is NULL in unittests. | |
159 static void ShowBubble(Browser* browser, | |
160 bool undo_value_is_ntp, | |
Peter Kasting
2013/01/17 23:48:42
Nit: All args should be aligned
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
161 const GURL &undo_url, | |
Peter Kasting
2013/01/17 23:48:42
Nit: & binds to type, not name
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
162 const GURL &new_home_page, | |
163 views::View* anchor_view); | |
164 static void HideBubble(); | |
165 | |
166 protected: | |
Peter Kasting
2013/01/17 23:48:42
Nit: Why protected? No one subclasses this class.
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
167 // views::BubbleDelegateView overrides: | |
168 virtual void Init() OVERRIDE; | |
169 | |
170 private: | |
171 HomePageUndoBubble(Browser* browser, | |
172 bool undo_value_is_ntp, | |
173 const GURL &undo_url, | |
174 const GURL &new_home_page, | |
175 views::View* anchor_view); | |
176 virtual ~HomePageUndoBubble(); | |
177 | |
178 // views::ButtonListener overrides: | |
Peter Kasting
2013/01/17 23:48:42
Nit: I've been trying to standardize on just "// v
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
179 virtual void ButtonPressed(views::Button* sender, | |
180 const ui::Event& event) OVERRIDE; | |
181 | |
182 // views::LinkListener overrides: | |
183 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | |
184 | |
185 // views::WidgetDelegate method. | |
Peter Kasting
2013/01/17 23:48:42
Nit: You don't directly subclass WidgetDelegate.
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
186 virtual void WindowClosing() OVERRIDE; | |
187 | |
188 static HomePageUndoBubble* sethomeundo_bubble_; | |
Peter Kasting
2013/01/17 23:48:42
Nit: No run-together words in variable names.
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
189 | |
190 enum HomePageUndoBubbleLinkIds { | |
Peter Kasting
2013/01/17 23:48:42
Nit: enums get declared atop the section... though
Tom Cassiotis
2013/01/18 15:18:49
Removed enum. Done.
| |
191 ID_LINK_UNDO = 1, | |
192 }; | |
193 | |
194 Browser* browser_; | |
195 bool undo_value_is_ntp_; | |
196 GURL undo_url_; | |
197 GURL new_home_page_; | |
Tom Cassiotis
2013/01/18 15:18:49
new_home_page_ was not used as we removed the hype
| |
198 | |
199 DISALLOW_COPY_AND_ASSIGN(HomePageUndoBubble); | |
200 }; | |
201 | |
202 // static | |
203 HomePageUndoBubble* HomePageUndoBubble::sethomeundo_bubble_ = NULL; | |
204 | |
205 void HomePageUndoBubble::ShowBubble(Browser* browser, | |
206 bool undo_value_is_ntp, | |
207 const GURL &undo_url, | |
208 const GURL &new_home_page, | |
209 views::View* anchor_view) { | |
210 HideBubble(); | |
211 sethomeundo_bubble_ = new HomePageUndoBubble(browser, undo_value_is_ntp, | |
212 undo_url, new_home_page, | |
213 anchor_view); | |
214 views::BubbleDelegateView::CreateBubble(sethomeundo_bubble_); | |
215 sethomeundo_bubble_->StartFade(true); | |
216 } | |
217 | |
218 void HomePageUndoBubble::HideBubble() { | |
219 if (sethomeundo_bubble_ != NULL) | |
220 sethomeundo_bubble_->GetWidget()->Close(); | |
Peter Kasting
2013/01/17 23:48:42
Nit; Indent 2, not 3
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
221 } | |
222 | |
223 HomePageUndoBubble::HomePageUndoBubble( | |
224 Browser* browser, | |
225 bool undo_value_is_ntp, | |
226 const GURL &undo_url, | |
227 const GURL &new_home_page, | |
228 views::View* anchor_view) | |
229 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT), | |
Peter Kasting
2013/01/17 23:48:42
Nit: Indent 4, not 8
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
230 browser_(browser), | |
231 undo_value_is_ntp_(undo_value_is_ntp), | |
232 undo_url_(undo_url), | |
233 new_home_page_(new_home_page) { | |
234 } | |
235 | |
236 HomePageUndoBubble::~HomePageUndoBubble() { | |
237 } | |
238 | |
239 void HomePageUndoBubble::Init() { | |
240 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
241 views::GridLayout* layout = new views::GridLayout(this); | |
242 SetLayoutManager(layout); | |
243 | |
244 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
245 | |
246 // Create two columns for the message and the undo link | |
Peter Kasting
2013/01/17 23:48:42
Nit: Trailing period
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
247 views::ColumnSet* cs = layout->AddColumnSet(0); | |
248 cs = layout->AddColumnSet(1); | |
Peter Kasting
2013/01/17 23:48:42
Make sure you test all this in RTL (try starting w
Tom Cassiotis
2013/01/18 15:18:49
Verified that is works.
| |
249 cs->AddColumn(views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | |
Peter Kasting
2013/01/17 23:48:42
I don't think you want CENTER vertical alignment f
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
250 views::GridLayout::USE_PREF, 0, 0); | |
251 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | |
252 cs->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 0, | |
253 views::GridLayout::USE_PREF, 0, 0); | |
254 | |
255 views::Label* message_label = new views::Label( | |
256 l10n_util::GetStringUTF16(IDS_TOOLBAR_INFORM_SET_HOME_PAGE)); | |
257 message_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
258 message_label->SetMultiLine(true); | |
Peter Kasting
2013/01/17 23:48:42
If you're using a multiline label, you need to giv
Tom Cassiotis
2013/01/18 15:18:49
This was remnants of an alternative approach. Fixe
| |
259 layout->StartRow(0, 1); | |
260 layout->AddView(message_label); | |
261 | |
262 views::Link* undo_link = new views::Link( | |
263 l10n_util::GetStringUTF16(IDS_ONE_CLICK_BUBBLE_UNDO)); | |
264 undo_link->set_id(ID_LINK_UNDO); | |
265 undo_link->set_listener(this); | |
266 layout->AddView(undo_link); | |
267 | |
268 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
Peter Kasting
2013/01/17 23:48:42
Why this?
Peter Kasting
2013/01/17 23:49:46
Oh, I see you have one at top too.
I'd remove bot
Tom Cassiotis
2013/01/18 15:18:49
I thought it needed some padding. Without the padd
| |
269 } | |
270 | |
271 void HomePageUndoBubble::ButtonPressed(views::Button* sender, | |
Peter Kasting
2013/01/17 23:48:42
Why do we need to override this function at all?
Tom Cassiotis
2013/01/18 15:18:49
We do not, removed.
Done.
| |
272 const ui::Event& event) { | |
273 GetWidget()->Close(); | |
274 } | |
275 | |
276 void HomePageUndoBubble::LinkClicked(views::Link* source, int event_flags) { | |
277 if (source->id() == ID_LINK_UNDO) { | |
278 browser_->profile()->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, | |
279 undo_value_is_ntp_); | |
280 browser_->profile()->GetPrefs()->SetString(prefs::kHomePage, | |
281 undo_url_.spec()); | |
282 GetWidget()->Close(); | |
Peter Kasting
2013/01/17 23:48:42
Nit: Perhaps this should call HideBubble() instead
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
283 } | |
284 } | |
285 | |
286 void HomePageUndoBubble::WindowClosing() { | |
287 // We have to reset |sethomeundo_bubble_| here, not in our destructor, | |
288 // because we'll be destroyed asynchronously and the shown state will | |
Peter Kasting
2013/01/17 23:48:42
Nit: Extra space. Also "will" -> "could", I belie
Tom Cassiotis
2013/01/18 15:18:49
This is a comment I copied from another singleton
| |
289 // be checked before then. | |
290 DCHECK_EQ(sethomeundo_bubble_, this); | |
Peter Kasting
2013/01/17 23:48:42
Nit: (expected, actual)
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
291 sethomeundo_bubble_ = NULL; | |
292 } | |
293 | |
150 } // namespace | 294 } // namespace |
151 | 295 |
296 HomeImageButton::HomeImageButton( | |
297 views::ButtonListener* listener, | |
298 Browser* browser) | |
299 : views::ImageButton(listener), | |
300 browser_(browser) { | |
301 } | |
302 | |
303 HomeImageButton::~HomeImageButton() { | |
304 } | |
305 | |
306 bool HomeImageButton::GetDropFormats( | |
307 int* formats, | |
308 std::set<OSExchangeData::CustomFormat>* custom_formats) { | |
309 *formats = ui::OSExchangeData::URL; | |
310 return true; | |
311 } | |
312 | |
313 bool HomeImageButton::CanDrop(const OSExchangeData& data) { | |
314 return data.HasURL(); | |
315 } | |
316 | |
317 int HomeImageButton::OnDragUpdated(const ui::DropTargetEvent& event) { | |
318 if (event.source_operations() & ui::DragDropTypes::DRAG_LINK) { | |
Peter Kasting
2013/01/17 23:48:42
Nit: {} not needed. You could also use ?: to make
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
319 return ui::DragDropTypes::DRAG_LINK; | |
320 } | |
321 return ui::DragDropTypes::DRAG_NONE; | |
322 } | |
323 | |
324 int HomeImageButton::OnPerformDrop(const ui::DropTargetEvent& event) { | |
325 GURL new_homepage_url; | |
326 string16 title; | |
327 if (event.data().GetURLAndTitle(&new_homepage_url, &title) && | |
328 new_homepage_url.is_valid()) { | |
329 PrefService* preferences = browser_->profile()->GetPrefs(); | |
Peter Kasting
2013/01/17 23:48:42
Nit: |prefs| is more common a name (and might avoi
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
330 | |
Peter Kasting
2013/01/17 23:48:42
Nit: Unnecessary newline
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
331 const bool old_is_ntp = preferences->GetBoolean( | |
Peter Kasting
2013/01/17 23:48:42
Nit: While I personally like them, Chrome code gen
Tom Cassiotis
2013/01/18 15:18:49
Done.
| |
332 prefs::kHomePageIsNewTabPage); | |
333 const GURL old_homepage(preferences->GetString( | |
334 prefs::kHomePage)); | |
335 | |
336 preferences->SetBoolean(prefs::kHomePageIsNewTabPage, false); | |
337 preferences->SetString(prefs::kHomePage, new_homepage_url.spec()); | |
338 | |
339 HomePageUndoBubble::ShowBubble(browser_, old_is_ntp, old_homepage, | |
340 new_homepage_url, this); | |
341 } | |
342 return ui::DragDropTypes::DRAG_NONE; | |
343 } | |
344 | |
152 // static | 345 // static |
153 const char ToolbarView::kViewClassName[] = "browser/ui/views/ToolbarView"; | 346 const char ToolbarView::kViewClassName[] = "browser/ui/views/ToolbarView"; |
154 // The space between items is 3 px in general. | 347 // The space between items is 3 px in general. |
155 const int ToolbarView::kStandardSpacing = 3; | 348 const int ToolbarView::kStandardSpacing = 3; |
156 // The top of the toolbar has an edge we have to skip over in addition to the | 349 // The top of the toolbar has an edge we have to skip over in addition to the |
157 // above spacing. | 350 // above spacing. |
158 const int ToolbarView::kVertSpacing = 5; | 351 const int ToolbarView::kVertSpacing = 5; |
159 | 352 |
160 //////////////////////////////////////////////////////////////////////////////// | 353 //////////////////////////////////////////////////////////////////////////////// |
161 // ToolbarView, public: | 354 // ToolbarView, public: |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 LocationBarView::POPUP : LocationBarView::NORMAL); | 432 LocationBarView::POPUP : LocationBarView::NORMAL); |
240 | 433 |
241 reload_ = new ReloadButton(location_bar_, | 434 reload_ = new ReloadButton(location_bar_, |
242 browser_->command_controller()->command_updater()); | 435 browser_->command_controller()->command_updater()); |
243 reload_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 436 reload_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
244 ui::EF_MIDDLE_MOUSE_BUTTON); | 437 ui::EF_MIDDLE_MOUSE_BUTTON); |
245 reload_->set_tag(IDC_RELOAD); | 438 reload_->set_tag(IDC_RELOAD); |
246 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); | 439 reload_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)); |
247 reload_->set_id(VIEW_ID_RELOAD_BUTTON); | 440 reload_->set_id(VIEW_ID_RELOAD_BUTTON); |
248 | 441 |
249 home_ = new views::ImageButton(this); | 442 home_ = new HomeImageButton(this, browser_); |
250 home_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 443 home_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
251 ui::EF_MIDDLE_MOUSE_BUTTON); | 444 ui::EF_MIDDLE_MOUSE_BUTTON); |
252 home_->set_tag(IDC_HOME); | 445 home_->set_tag(IDC_HOME); |
253 home_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_HOME)); | 446 home_->SetTooltipText(l10n_util::GetStringUTF16(IDS_TOOLTIP_HOME)); |
254 home_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME)); | 447 home_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME)); |
255 home_->set_id(VIEW_ID_HOME_BUTTON); | 448 home_->set_id(VIEW_ID_HOME_BUTTON); |
256 | 449 |
257 browser_actions_ = new BrowserActionsContainer(browser_, this); | 450 browser_actions_ = new BrowserActionsContainer(browser_, this); |
258 | 451 |
259 #if defined(OS_WIN) && !defined(USE_AURA) | 452 #if defined(OS_WIN) && !defined(USE_AURA) |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::STATE_NORMAL)); | 1097 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::STATE_NORMAL)); |
905 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::STATE_HOVERED)); | 1098 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::STATE_HOVERED)); |
906 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::STATE_PRESSED)); | 1099 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::STATE_PRESSED)); |
907 SchedulePaint(); | 1100 SchedulePaint(); |
908 } | 1101 } |
909 | 1102 |
910 void ToolbarView::OnShowHomeButtonChanged() { | 1103 void ToolbarView::OnShowHomeButtonChanged() { |
911 Layout(); | 1104 Layout(); |
912 SchedulePaint(); | 1105 SchedulePaint(); |
913 } | 1106 } |
OLD | NEW |