Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

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

Powered by Google App Engine
This is Rietveld 408576698