OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/location_bar/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "chrome/browser/favicon/favicon_tab_helper.h" | 21 #include "chrome/browser/favicon/favicon_tab_helper.h" |
22 #include "chrome/browser/instant/instant_controller.h" | 22 #include "chrome/browser/instant/instant_controller.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/search_engines/template_url.h" | 24 #include "chrome/browser/search_engines/template_url.h" |
25 #include "chrome/browser/search_engines/template_url_service.h" | 25 #include "chrome/browser/search_engines/template_url_service.h" |
26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
29 #include "chrome/browser/ui/view_ids.h" | 29 #include "chrome/browser/ui/view_ids.h" |
30 #include "chrome/browser/ui/views/browser_dialogs.h" | 30 #include "chrome/browser/ui/views/browser_dialogs.h" |
31 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" | |
31 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" | 32 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" |
32 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 33 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
33 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 34 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
34 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 35 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
35 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 36 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
36 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 37 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
37 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 38 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
38 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 39 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
39 #include "chrome/browser/ui/views/location_bar/star_view.h" | 40 #include "chrome/browser/ui/views/location_bar/star_view.h" |
40 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 41 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
41 #include "chrome/common/chrome_notification_types.h" | 42 #include "chrome/common/chrome_notification_types.h" |
42 #include "chrome/common/chrome_switches.h" | 43 #include "chrome/common/chrome_switches.h" |
44 #include "chrome/common/extensions/extension_switch_utils.h" | |
43 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
44 #include "content/public/browser/notification_service.h" | 46 #include "content/public/browser/notification_service.h" |
45 #include "content/public/browser/render_widget_host_view.h" | 47 #include "content/public/browser/render_widget_host_view.h" |
46 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
47 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
48 #include "grit/theme_resources.h" | 50 #include "grit/theme_resources.h" |
49 #include "grit/theme_resources_standard.h" | 51 #include "grit/theme_resources_standard.h" |
50 #include "ui/base/accessibility/accessible_view_state.h" | 52 #include "ui/base/accessibility/accessible_view_state.h" |
51 #include "ui/base/dragdrop/drag_drop_types.h" | 53 #include "ui/base/dragdrop/drag_drop_types.h" |
52 #include "ui/base/l10n/l10n_util.h" | 54 #include "ui/base/l10n/l10n_util.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), | 137 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), |
136 location_icon_view_(NULL), | 138 location_icon_view_(NULL), |
137 ev_bubble_view_(NULL), | 139 ev_bubble_view_(NULL), |
138 location_entry_view_(NULL), | 140 location_entry_view_(NULL), |
139 selected_keyword_view_(NULL), | 141 selected_keyword_view_(NULL), |
140 #if defined(OS_WIN) || defined(USE_AURA) | 142 #if defined(OS_WIN) || defined(USE_AURA) |
141 suggested_text_view_(NULL), | 143 suggested_text_view_(NULL), |
142 #endif | 144 #endif |
143 keyword_hint_view_(NULL), | 145 keyword_hint_view_(NULL), |
144 star_view_(NULL), | 146 star_view_(NULL), |
147 action_box_button_view_(NULL), | |
145 chrome_to_mobile_view_(NULL), | 148 chrome_to_mobile_view_(NULL), |
146 mode_(mode), | 149 mode_(mode), |
147 show_focus_rect_(false), | 150 show_focus_rect_(false), |
148 template_url_service_(NULL), | 151 template_url_service_(NULL), |
149 animation_offset_(0) { | 152 animation_offset_(0) { |
150 set_id(VIEW_ID_LOCATION_BAR); | 153 set_id(VIEW_ID_LOCATION_BAR); |
151 | 154 |
152 if (mode_ == NORMAL) { | 155 if (mode_ == NORMAL) { |
153 painter_.reset( | 156 painter_.reset( |
154 views::Painter::CreateImagePainter( | 157 views::Painter::CreateImagePainter( |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 keyword_hint_view_->SetFont(font_); | 225 keyword_hint_view_->SetFont(font_); |
223 | 226 |
224 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 227 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
225 ContentSettingImageView* content_blocked_view = | 228 ContentSettingImageView* content_blocked_view = |
226 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this); | 229 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this); |
227 content_setting_views_.push_back(content_blocked_view); | 230 content_setting_views_.push_back(content_blocked_view); |
228 AddChildView(content_blocked_view); | 231 AddChildView(content_blocked_view); |
229 content_blocked_view->SetVisible(false); | 232 content_blocked_view->SetVisible(false); |
230 } | 233 } |
231 | 234 |
235 bool action_box_enabled = extensions::switch_utils::IsActionBoxEnabled(); | |
236 | |
232 // Hide the star and Chrome To Mobile icons in popups and in the app launcher. | 237 // Hide the star and Chrome To Mobile icons in popups and in the app launcher. |
233 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { | 238 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL) && |
239 !action_box_enabled) { | |
234 star_view_ = new StarView(command_updater_); | 240 star_view_ = new StarView(command_updater_); |
235 AddChildView(star_view_); | 241 AddChildView(star_view_); |
236 star_view_->SetVisible(true); | 242 star_view_->SetVisible(true); |
237 | 243 |
238 // Also disable Chrome To Mobile for off-the-record and non-synced profiles, | 244 // Also disable Chrome To Mobile for off-the-record and non-synced profiles, |
239 // or if the feature is disabled by a command line flag or chrome://flags. | 245 // or if the feature is disabled by a command line flag or chrome://flags. |
240 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && | 246 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && |
241 ChromeToMobileService::IsChromeToMobileEnabled()) { | 247 ChromeToMobileService::IsChromeToMobileEnabled()) { |
242 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_); | 248 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_); |
243 AddChildView(chrome_to_mobile_view_); | 249 AddChildView(chrome_to_mobile_view_); |
244 ChromeToMobileService* service = | 250 ChromeToMobileService* service = |
245 ChromeToMobileServiceFactory::GetForProfile(profile_); | 251 ChromeToMobileServiceFactory::GetForProfile(profile_); |
246 service->RequestMobileListUpdate(); | 252 service->RequestMobileListUpdate(); |
247 chrome_to_mobile_view_->SetVisible(service->HasDevices()); | 253 chrome_to_mobile_view_->SetVisible(service->HasDevices()); |
248 } | 254 } |
249 } | 255 } |
250 | 256 |
257 if (action_box_enabled) { | |
258 action_box_button_view_ = new ActionBoxButtonView(); | |
259 AddChildView(action_box_button_view_); | |
not at google - send to devlin
2012/05/17 23:40:24
nit: could you combine this with the above stateme
yefimt
2012/05/18 00:20:02
Done.
| |
260 } | |
261 | |
251 // Initialize the location entry. We do this to avoid a black flash which is | 262 // Initialize the location entry. We do this to avoid a black flash which is |
252 // visible when the location entry has just been initialized. | 263 // visible when the location entry has just been initialized. |
253 Update(NULL); | 264 Update(NULL); |
254 | 265 |
255 OnChanged(); | 266 OnChanged(); |
256 } | 267 } |
257 | 268 |
258 bool LocationBarView::IsInitialized() const { | 269 bool LocationBarView::IsInitialized() const { |
259 return location_entry_view_ != NULL; | 270 return location_entry_view_ != NULL; |
260 } | 271 } |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 location_icon_width = location_icon_view_->GetPreferredSize().width(); | 571 location_icon_width = location_icon_view_->GetPreferredSize().width(); |
561 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + | 572 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + |
562 location_icon_width + kItemEditPadding); | 573 location_icon_width + kItemEditPadding); |
563 } | 574 } |
564 | 575 |
565 if (star_view_ && star_view_->visible()) | 576 if (star_view_ && star_view_->visible()) |
566 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); | 577 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); |
567 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) | 578 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) |
568 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + | 579 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + |
569 GetItemPadding(); | 580 GetItemPadding(); |
581 if (action_box_button_view_) | |
582 entry_width -= action_box_button_view_->GetPreferredSize().width() + | |
583 GetItemPadding(); | |
570 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 584 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
571 i != page_action_views_.end(); ++i) { | 585 i != page_action_views_.end(); ++i) { |
572 if ((*i)->visible()) | 586 if ((*i)->visible()) |
573 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); | 587 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
574 } | 588 } |
575 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); | 589 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); |
576 i != content_setting_views_.end(); ++i) { | 590 i != content_setting_views_.end(); ++i) { |
577 if ((*i)->visible()) | 591 if ((*i)->visible()) |
578 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); | 592 entry_width -= ((*i)->GetPreferredSize().width() + GetItemPadding()); |
579 } | 593 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 } | 650 } |
637 | 651 |
638 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { | 652 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { |
639 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); | 653 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); |
640 offset -= icon_width; | 654 offset -= icon_width; |
641 chrome_to_mobile_view_->SetBounds(offset, location_y, | 655 chrome_to_mobile_view_->SetBounds(offset, location_y, |
642 icon_width, location_height); | 656 icon_width, location_height); |
643 offset -= GetItemPadding(); | 657 offset -= GetItemPadding(); |
644 } | 658 } |
645 | 659 |
660 if (action_box_button_view_) { | |
661 int button_width = action_box_button_view_->GetPreferredSize().width(); | |
662 offset -= button_width; | |
663 action_box_button_view_->SetBounds(offset, location_y, button_width, | |
664 location_height); | |
665 offset -= GetItemPadding(); | |
666 } | |
667 | |
646 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 668 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
647 i != page_action_views_.end(); ++i) { | 669 i != page_action_views_.end(); ++i) { |
648 if ((*i)->visible()) { | 670 if ((*i)->visible()) { |
649 int page_action_width = (*i)->GetPreferredSize().width(); | 671 int page_action_width = (*i)->GetPreferredSize().width(); |
650 offset -= page_action_width; | 672 offset -= page_action_width; |
651 (*i)->SetBounds(offset, location_y, page_action_width, location_height); | 673 (*i)->SetBounds(offset, location_y, page_action_width, location_height); |
652 offset -= GetItemPadding(); | 674 offset -= GetItemPadding(); |
653 } | 675 } |
654 } | 676 } |
655 // We use a reverse_iterator here because we're laying out the views from | 677 // We use a reverse_iterator here because we're laying out the views from |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1303 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1282 !suggested_text_view_->text().empty(); | 1304 !suggested_text_view_->text().empty(); |
1283 } | 1305 } |
1284 | 1306 |
1285 #if !defined(USE_AURA) | 1307 #if !defined(USE_AURA) |
1286 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1308 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
1287 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1309 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
1288 } | 1310 } |
1289 #endif | 1311 #endif |
1290 #endif | 1312 #endif |
OLD | NEW |