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