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/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/ui/search/search_ui.h" | 35 #include "chrome/browser/ui/search/search_ui.h" |
36 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 36 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
37 #include "chrome/browser/ui/view_ids.h" | 37 #include "chrome/browser/ui/view_ids.h" |
38 #include "chrome/browser/ui/views/browser_dialogs.h" | 38 #include "chrome/browser/ui/views/browser_dialogs.h" |
39 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" | 39 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" |
40 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" | 40 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h" |
41 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" | 41 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" | 42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" |
43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" | 43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" |
44 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 44 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 45 #include "chrome/browser/ui/views/location_bar/metro_pin_view.h" |
45 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" | 46 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" |
46 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" | 47 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
47 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" | 48 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
48 #include "chrome/browser/ui/views/location_bar/star_view.h" | 49 #include "chrome/browser/ui/views/location_bar/star_view.h" |
49 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" | 50 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" |
50 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 51 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
51 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | 52 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
52 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 53 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
53 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" | 54 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" |
54 #include "chrome/browser/ui/webui/instant_ui.h" | 55 #include "chrome/browser/ui/webui/instant_ui.h" |
(...skipping 13 matching lines...) Expand all Loading... |
68 #include "ui/base/resource/resource_bundle.h" | 69 #include "ui/base/resource/resource_bundle.h" |
69 #include "ui/base/theme_provider.h" | 70 #include "ui/base/theme_provider.h" |
70 #include "ui/gfx/canvas.h" | 71 #include "ui/gfx/canvas.h" |
71 #include "ui/gfx/color_utils.h" | 72 #include "ui/gfx/color_utils.h" |
72 #include "ui/gfx/image/image.h" | 73 #include "ui/gfx/image/image.h" |
73 #include "ui/gfx/skia_util.h" | 74 #include "ui/gfx/skia_util.h" |
74 #include "ui/views/border.h" | 75 #include "ui/views/border.h" |
75 #include "ui/views/button_drag_utils.h" | 76 #include "ui/views/button_drag_utils.h" |
76 #include "ui/views/controls/label.h" | 77 #include "ui/views/controls/label.h" |
77 | 78 |
| 79 #if defined(OS_WIN) |
| 80 #include "base/win/metro.h" |
| 81 #endif |
| 82 |
78 #if defined(OS_WIN) && !defined(USE_AURA) | 83 #if defined(OS_WIN) && !defined(USE_AURA) |
79 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" | 84 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
80 #endif | 85 #endif |
81 | 86 |
82 #if !defined(OS_CHROMEOS) | 87 #if !defined(OS_CHROMEOS) |
83 #include "chrome/browser/ui/views/first_run_bubble.h" | 88 #include "chrome/browser/ui/views/first_run_bubble.h" |
84 #endif | 89 #endif |
85 | 90 |
86 #if defined(USE_AURA) | 91 #if defined(USE_AURA) |
87 #include "ui/compositor/layer.h" | 92 #include "ui/compositor/layer.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 location_icon_view_(NULL), | 180 location_icon_view_(NULL), |
176 ev_bubble_view_(NULL), | 181 ev_bubble_view_(NULL), |
177 location_entry_view_(NULL), | 182 location_entry_view_(NULL), |
178 selected_keyword_view_(NULL), | 183 selected_keyword_view_(NULL), |
179 suggested_text_view_(NULL), | 184 suggested_text_view_(NULL), |
180 keyword_hint_view_(NULL), | 185 keyword_hint_view_(NULL), |
181 zoom_view_(NULL), | 186 zoom_view_(NULL), |
182 star_view_(NULL), | 187 star_view_(NULL), |
183 action_box_button_view_(NULL), | 188 action_box_button_view_(NULL), |
184 chrome_to_mobile_view_(NULL), | 189 chrome_to_mobile_view_(NULL), |
| 190 metro_pin_view_(NULL), |
185 mode_(mode), | 191 mode_(mode), |
186 show_focus_rect_(false), | 192 show_focus_rect_(false), |
187 template_url_service_(NULL), | 193 template_url_service_(NULL), |
188 animation_offset_(0), | 194 animation_offset_(0), |
189 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { | 195 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { |
190 set_id(VIEW_ID_LOCATION_BAR); | 196 set_id(VIEW_ID_LOCATION_BAR); |
191 | 197 |
192 if (mode_ == NORMAL) { | 198 if (mode_ == NORMAL) { |
193 painter_.reset( | 199 painter_.reset( |
194 views::Painter::CreateImagePainter( | 200 views::Painter::CreateImagePainter( |
(...skipping 28 matching lines...) Expand all Loading... |
223 font_ = rb.GetFont(ui::ResourceBundle::MediumFont); | 229 font_ = rb.GetFont(ui::ResourceBundle::MediumFont); |
224 } | 230 } |
225 | 231 |
226 // If this makes the font too big, try to make it smaller so it will fit. | 232 // If this makes the font too big, try to make it smaller so it will fit. |
227 const int height = GetInternalHeight(true); | 233 const int height = GetInternalHeight(true); |
228 while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1)) | 234 while ((font_.GetHeight() > height) && (font_.GetFontSize() > 1)) |
229 font_ = font_.DeriveFont(-1); | 235 font_ = font_.DeriveFont(-1); |
230 | 236 |
231 location_icon_view_ = new LocationIconView(this); | 237 location_icon_view_ = new LocationIconView(this); |
232 AddChildView(location_icon_view_); | 238 AddChildView(location_icon_view_); |
233 location_icon_view_->SetVisible(true); | |
234 location_icon_view_->set_drag_controller(this); | 239 location_icon_view_->set_drag_controller(this); |
235 | 240 |
236 ev_bubble_view_ = | 241 ev_bubble_view_ = |
237 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, | 242 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, |
238 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); | 243 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); |
239 AddChildView(ev_bubble_view_); | 244 AddChildView(ev_bubble_view_); |
240 ev_bubble_view_->SetVisible(false); | 245 ev_bubble_view_->SetVisible(false); |
241 ev_bubble_view_->set_drag_controller(this); | 246 ev_bubble_view_->set_drag_controller(this); |
242 | 247 |
243 // URL edit field. | 248 // URL edit field. |
(...skipping 30 matching lines...) Expand all Loading... |
274 | 279 |
275 if (extensions::switch_utils::IsActionBoxEnabled()) { | 280 if (extensions::switch_utils::IsActionBoxEnabled()) { |
276 action_box_button_view_ = new ActionBoxButtonView( | 281 action_box_button_view_ = new ActionBoxButtonView( |
277 extensions::ExtensionSystem::Get(profile_)->extension_service()); | 282 extensions::ExtensionSystem::Get(profile_)->extension_service()); |
278 AddChildView(action_box_button_view_); | 283 AddChildView(action_box_button_view_); |
279 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { | 284 } else if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { |
280 // Note: condition above means that the star and ChromeToMobile icons are | 285 // Note: condition above means that the star and ChromeToMobile icons are |
281 // hidden in popups and in the app launcher. | 286 // hidden in popups and in the app launcher. |
282 star_view_ = new StarView(command_updater_); | 287 star_view_ = new StarView(command_updater_); |
283 AddChildView(star_view_); | 288 AddChildView(star_view_); |
284 star_view_->SetVisible(true); | 289 |
| 290 // Add the metro pin view, if this is windows and we are running in Metro |
| 291 // mode. |
| 292 #if defined(OS_WIN) |
| 293 if (base::win::IsMetroProcess()) { |
| 294 metro_pin_view_ = new MetroPinView(command_updater_); |
| 295 AddChildView(metro_pin_view_); |
| 296 } |
| 297 #endif |
285 | 298 |
286 // Also disable Chrome To Mobile for off-the-record and non-synced profiles, | 299 // Also disable Chrome To Mobile for off-the-record and non-synced profiles, |
287 // or if the feature is disabled by a command line flag or chrome://flags. | 300 // or if the feature is disabled by a command line flag or chrome://flags. |
288 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && | 301 if (!profile_->IsOffTheRecord() && profile_->IsSyncAccessible() && |
289 ChromeToMobileService::IsChromeToMobileEnabled()) { | 302 ChromeToMobileService::IsChromeToMobileEnabled()) { |
290 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_); | 303 chrome_to_mobile_view_ = new ChromeToMobileView(this, command_updater_); |
291 AddChildView(chrome_to_mobile_view_); | 304 AddChildView(chrome_to_mobile_view_); |
292 ChromeToMobileService* service = | 305 ChromeToMobileService* service = |
293 ChromeToMobileServiceFactory::GetForProfile(profile_); | 306 ChromeToMobileServiceFactory::GetForProfile(profile_); |
294 service->RequestMobileListUpdate(); | 307 service->RequestMobileListUpdate(); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 | 507 |
495 void LocationBarView::SetStarToggled(bool on) { | 508 void LocationBarView::SetStarToggled(bool on) { |
496 if (star_view_) | 509 if (star_view_) |
497 star_view_->SetToggled(on); | 510 star_view_->SetToggled(on); |
498 } | 511 } |
499 | 512 |
500 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { | 513 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { |
501 chrome::ShowBookmarkBubbleView(star_view_, profile_, url, newly_bookmarked); | 514 chrome::ShowBookmarkBubbleView(star_view_, profile_, url, newly_bookmarked); |
502 } | 515 } |
503 | 516 |
| 517 void LocationBarView::SetMetroPinnedState(bool is_pinned) { |
| 518 if (metro_pin_view_) |
| 519 metro_pin_view_->SetIsPinned(is_pinned); |
| 520 } |
| 521 |
504 void LocationBarView::SetZoomIconTooltipPercent(int zoom_percent) { | 522 void LocationBarView::SetZoomIconTooltipPercent(int zoom_percent) { |
505 zoom_view_->SetZoomIconTooltipPercent(zoom_percent); | 523 zoom_view_->SetZoomIconTooltipPercent(zoom_percent); |
506 } | 524 } |
507 | 525 |
508 void LocationBarView::SetZoomIconState( | 526 void LocationBarView::SetZoomIconState( |
509 ZoomController::ZoomIconState zoom_icon_state) { | 527 ZoomController::ZoomIconState zoom_icon_state) { |
510 zoom_view_->SetZoomIconState(zoom_icon_state); | 528 zoom_view_->SetZoomIconState(zoom_icon_state); |
511 | 529 |
512 Layout(); | 530 Layout(); |
513 SchedulePaint(); | 531 SchedulePaint(); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 // We'll adjust this width and take it out of |entry_width| below. | 666 // We'll adjust this width and take it out of |entry_width| below. |
649 } else { | 667 } else { |
650 location_icon_view_->SetVisible(true); | 668 location_icon_view_->SetVisible(true); |
651 location_icon_width = location_icon_view_->GetPreferredSize().width(); | 669 location_icon_width = location_icon_view_->GetPreferredSize().width(); |
652 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + | 670 entry_width -= (kEdgeThickness + GetEdgeItemPadding() + |
653 location_icon_width + kItemEditPadding); | 671 location_icon_width + kItemEditPadding); |
654 } | 672 } |
655 | 673 |
656 if (star_view_ && star_view_->visible()) | 674 if (star_view_ && star_view_->visible()) |
657 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); | 675 entry_width -= star_view_->GetPreferredSize().width() + GetItemPadding(); |
| 676 if (metro_pin_view_ && metro_pin_view_->visible()) |
| 677 entry_width -= metro_pin_view_->GetPreferredSize().width() + |
| 678 GetItemPadding(); |
658 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { | 679 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { |
659 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + | 680 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() + |
660 GetItemPadding(); | 681 GetItemPadding(); |
661 } | 682 } |
662 int action_box_button_width = location_height; | 683 int action_box_button_width = location_height; |
663 if (action_box_button_view_) | 684 if (action_box_button_view_) |
664 entry_width -= action_box_button_width + GetItemPadding(); | 685 entry_width -= action_box_button_width + GetItemPadding(); |
665 for (PageActionViews::const_iterator i(page_action_views_.begin()); | 686 for (PageActionViews::const_iterator i(page_action_views_.begin()); |
666 i != page_action_views_.end(); ++i) { | 687 i != page_action_views_.end(); ++i) { |
667 if ((*i)->visible()) | 688 if ((*i)->visible()) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 } | 757 } |
737 | 758 |
738 if (star_view_ && star_view_->visible()) { | 759 if (star_view_ && star_view_->visible()) { |
739 offset += star_view_->GetBuiltInHorizontalPadding(); | 760 offset += star_view_->GetBuiltInHorizontalPadding(); |
740 int star_width = star_view_->GetPreferredSize().width(); | 761 int star_width = star_view_->GetPreferredSize().width(); |
741 offset -= star_width; | 762 offset -= star_width; |
742 star_view_->SetBounds(offset, location_y, star_width, location_height); | 763 star_view_->SetBounds(offset, location_y, star_width, location_height); |
743 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding(); | 764 offset -= GetItemPadding() - star_view_->GetBuiltInHorizontalPadding(); |
744 } | 765 } |
745 | 766 |
| 767 if (metro_pin_view_ && metro_pin_view_->visible()) { |
| 768 offset += metro_pin_view_->GetBuiltInHorizontalPadding(); |
| 769 int pin_width = metro_pin_view_->GetPreferredSize().width(); |
| 770 offset -= pin_width; |
| 771 metro_pin_view_->SetBounds(offset, location_y, pin_width, location_height); |
| 772 offset -= GetItemPadding() - metro_pin_view_->GetBuiltInHorizontalPadding(); |
| 773 } |
| 774 |
746 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { | 775 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) { |
747 offset += chrome_to_mobile_view_->GetBuiltInHorizontalPadding(); | 776 offset += chrome_to_mobile_view_->GetBuiltInHorizontalPadding(); |
748 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); | 777 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width(); |
749 offset -= icon_width; | 778 offset -= icon_width; |
750 chrome_to_mobile_view_->SetBounds(offset, location_y, | 779 chrome_to_mobile_view_->SetBounds(offset, location_y, |
751 icon_width, location_height); | 780 icon_width, location_height); |
752 offset -= GetItemPadding() - | 781 offset -= GetItemPadding() - |
753 chrome_to_mobile_view_->GetBuiltInHorizontalPadding(); | 782 chrome_to_mobile_view_->GetBuiltInHorizontalPadding(); |
754 } | 783 } |
755 | 784 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 | 1149 |
1121 // On startup we sometimes haven't loaded any extensions. This makes sure | 1150 // On startup we sometimes haven't loaded any extensions. This makes sure |
1122 // we catch up when the extensions (and any page actions) load. | 1151 // we catch up when the extensions (and any page actions) load. |
1123 if (page_actions_ != new_page_actions) { | 1152 if (page_actions_ != new_page_actions) { |
1124 page_actions_.swap(new_page_actions); | 1153 page_actions_.swap(new_page_actions); |
1125 DeletePageActionViews(); // Delete the old views (if any). | 1154 DeletePageActionViews(); // Delete the old views (if any). |
1126 | 1155 |
1127 page_action_views_.resize(page_actions_.size()); | 1156 page_action_views_.resize(page_actions_.size()); |
1128 View* right_anchor = chrome_to_mobile_view_; | 1157 View* right_anchor = chrome_to_mobile_view_; |
1129 if (!right_anchor) | 1158 if (!right_anchor) |
| 1159 right_anchor = metro_pin_view_; |
| 1160 if (!right_anchor) |
1130 right_anchor = star_view_; | 1161 right_anchor = star_view_; |
1131 if (!right_anchor) | 1162 if (!right_anchor) |
1132 right_anchor = action_box_button_view_; | 1163 right_anchor = action_box_button_view_; |
1133 DCHECK(right_anchor); | 1164 DCHECK(right_anchor); |
1134 | 1165 |
1135 // Add the page actions in reverse order, so that the child views are | 1166 // Add the page actions in reverse order, so that the child views are |
1136 // inserted in left-to-right order for accessibility. | 1167 // inserted in left-to-right order for accessibility. |
1137 for (int i = page_actions_.size() - 1; i >= 0; --i) { | 1168 for (int i = page_actions_.size() - 1; i >= 0; --i) { |
1138 page_action_views_[i] = new PageActionWithBadgeView( | 1169 page_action_views_[i] = new PageActionWithBadgeView( |
1139 delegate_->CreatePageActionImageView(this, page_actions_[i])); | 1170 delegate_->CreatePageActionImageView(this, page_actions_[i])); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1494 } | 1525 } |
1495 | 1526 |
1496 void LocationBarView::CleanupFadeAnimation() { | 1527 void LocationBarView::CleanupFadeAnimation() { |
1497 // Since we're no longer animating we don't need our layer. | 1528 // Since we're no longer animating we don't need our layer. |
1498 SetPaintToLayer(false); | 1529 SetPaintToLayer(false); |
1499 // Bubble labels don't need a transparent background anymore. | 1530 // Bubble labels don't need a transparent background anymore. |
1500 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1531 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
1501 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1532 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
1502 } | 1533 } |
1503 #endif // USE_AURA | 1534 #endif // USE_AURA |
OLD | NEW |