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

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

Issue 9443007: Add Chrome To Mobile Service and Views Page Action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bail on empty GetOAuth2LoginRefreshToken(). Created 8 years, 9 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
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #if defined(TOOLKIT_USES_GTK) 7 #if defined(TOOLKIT_USES_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <map> 12 #include <map>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/app/chrome_command_ids.h" 17 #include "chrome/app/chrome_command_ids.h"
18 #include "chrome/browser/alternate_nav_url_fetcher.h" 18 #include "chrome/browser/alternate_nav_url_fetcher.h"
19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" 19 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
20 #include "chrome/browser/chrome_to_mobile_service.h"
21 #include "chrome/browser/chrome_to_mobile_service_factory.h"
20 #include "chrome/browser/defaults.h" 22 #include "chrome/browser/defaults.h"
21 #include "chrome/browser/extensions/extension_browser_event_router.h" 23 #include "chrome/browser/extensions/extension_browser_event_router.h"
22 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
23 #include "chrome/browser/favicon/favicon_tab_helper.h" 25 #include "chrome/browser/favicon/favicon_tab_helper.h"
24 #include "chrome/browser/instant/instant_controller.h" 26 #include "chrome/browser/instant/instant_controller.h"
25 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/search_engines/template_url.h" 28 #include "chrome/browser/search_engines/template_url.h"
27 #include "chrome/browser/search_engines/template_url_service.h" 29 #include "chrome/browser/search_engines/template_url_service.h"
28 #include "chrome/browser/search_engines/template_url_service_factory.h" 30 #include "chrome/browser/search_engines/template_url_service_factory.h"
29 #include "chrome/browser/ui/browser.h" 31 #include "chrome/browser/ui/browser.h"
30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
31 #include "chrome/browser/ui/view_ids.h" 33 #include "chrome/browser/ui/view_ids.h"
32 #include "chrome/browser/ui/views/browser_dialogs.h" 34 #include "chrome/browser/ui/views/browser_dialogs.h"
35 #include "chrome/browser/ui/views/location_bar/chrome_to_mobile_view.h"
33 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 36 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
34 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 37 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
35 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 38 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
36 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 39 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
37 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 40 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
38 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 41 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
39 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 42 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
40 #include "chrome/browser/ui/views/location_bar/star_view.h" 43 #include "chrome/browser/ui/views/location_bar/star_view.h"
41 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 44 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
42 #include "chrome/common/chrome_notification_types.h" 45 #include "chrome/common/chrome_notification_types.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)), 131 content::PAGE_TRANSITION_FROM_ADDRESS_BAR)),
129 location_icon_view_(NULL), 132 location_icon_view_(NULL),
130 ev_bubble_view_(NULL), 133 ev_bubble_view_(NULL),
131 location_entry_view_(NULL), 134 location_entry_view_(NULL),
132 selected_keyword_view_(NULL), 135 selected_keyword_view_(NULL),
133 #if defined(OS_WIN) || defined(USE_AURA) 136 #if defined(OS_WIN) || defined(USE_AURA)
134 suggested_text_view_(NULL), 137 suggested_text_view_(NULL),
135 #endif 138 #endif
136 keyword_hint_view_(NULL), 139 keyword_hint_view_(NULL),
137 star_view_(NULL), 140 star_view_(NULL),
141 chrome_to_mobile_view_(NULL),
138 mode_(mode), 142 mode_(mode),
139 show_focus_rect_(false), 143 show_focus_rect_(false),
140 template_url_service_(NULL), 144 template_url_service_(NULL),
141 animation_offset_(0) { 145 animation_offset_(0) {
142 set_id(VIEW_ID_LOCATION_BAR); 146 set_id(VIEW_ID_LOCATION_BAR);
143 147
144 if (mode_ == NORMAL) { 148 if (mode_ == NORMAL) {
145 painter_.reset( 149 painter_.reset(
146 views::Painter::CreateImagePainter( 150 views::Painter::CreateImagePainter(
147 *ResourceBundle::GetSharedInstance().GetImageNamed( 151 *ResourceBundle::GetSharedInstance().GetImageNamed(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 keyword_hint_view_->SetFont(font_); 220 keyword_hint_view_->SetFont(font_);
217 221
218 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 222 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
219 ContentSettingImageView* content_blocked_view = 223 ContentSettingImageView* content_blocked_view =
220 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this); 224 new ContentSettingImageView(static_cast<ContentSettingsType>(i), this);
221 content_setting_views_.push_back(content_blocked_view); 225 content_setting_views_.push_back(content_blocked_view);
222 AddChildView(content_blocked_view); 226 AddChildView(content_blocked_view);
223 content_blocked_view->SetVisible(false); 227 content_blocked_view->SetVisible(false);
224 } 228 }
225 229
226 // The star is not visible in popups and in the app launcher. 230 // Hide the star and Chrome To Mobile icons in popups and in the app launcher.
227 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) { 231 if (browser_defaults::bookmarks_enabled && (mode_ == NORMAL)) {
228 star_view_ = new StarView(browser_->command_updater()); 232 star_view_ = new StarView(browser_->command_updater());
229 AddChildView(star_view_); 233 AddChildView(star_view_);
230 star_view_->SetVisible(true); 234 star_view_->SetVisible(true);
235
236 // Also disable Chrome To Mobile for off-the-record and non-synced profiles.
237 Profile* profile = browser_->profile();
238 if (!profile->IsOffTheRecord() && profile->IsSyncAccessible()) {
239 chrome_to_mobile_view_ =
240 new ChromeToMobileView(this, browser_->command_updater());
241 AddChildView(chrome_to_mobile_view_);
242 ChromeToMobileService* service =
243 ChromeToMobileServiceFactory::GetForProfile(browser_->profile());
244 service->RequestMobileListUpdate();
245 chrome_to_mobile_view_->SetVisible(!service->mobiles().empty());
246 }
231 } 247 }
232 248
233 // Initialize the location entry. We do this to avoid a black flash which is 249 // Initialize the location entry. We do this to avoid a black flash which is
234 // visible when the location entry has just been initialized. 250 // visible when the location entry has just been initialized.
235 Update(NULL); 251 Update(NULL);
236 252
237 OnChanged(); 253 OnChanged();
238 } 254 }
239 255
240 bool LocationBarView::IsInitialized() const { 256 bool LocationBarView::IsInitialized() const {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 FocusLocation(select_all); 311 FocusLocation(select_all);
296 } 312 }
297 313
298 void LocationBarView::SetAnimationOffset(int offset) { 314 void LocationBarView::SetAnimationOffset(int offset) {
299 animation_offset_ = offset; 315 animation_offset_ = offset;
300 } 316 }
301 317
302 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { 318 void LocationBarView::Update(const WebContents* tab_for_state_restoring) {
303 bool star_enabled = star_view_ && !model_->input_in_progress() && 319 bool star_enabled = star_view_ && !model_->input_in_progress() &&
304 edit_bookmarks_enabled_.GetValue(); 320 edit_bookmarks_enabled_.GetValue();
305 browser_->command_updater()->UpdateCommandEnabled( 321 CommandUpdater* command_updater = browser_->command_updater();
306 IDC_BOOKMARK_PAGE, star_enabled); 322 command_updater->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
307 if (star_view_) 323 if (star_view_)
308 star_view_->SetVisible(star_enabled); 324 star_view_->SetVisible(star_enabled);
325
326 Profile* profile = browser_->profile();
327 bool chrome_to_mobile_enabled = chrome_to_mobile_view_ &&
328 !model_->input_in_progress() && profile->IsSyncAccessible() &&
329 !ChromeToMobileServiceFactory::GetForProfile(profile)->mobiles().empty();
330 command_updater->UpdateCommandEnabled(IDC_CHROME_TO_MOBILE_PAGE,
331 chrome_to_mobile_enabled);
332
309 RefreshContentSettingViews(); 333 RefreshContentSettingViews();
310 RefreshPageActionViews(); 334 RefreshPageActionViews();
311 // Don't Update in app launcher mode so that the location entry does not show 335 // Don't Update in app launcher mode so that the location entry does not show
312 // a URL or security background. 336 // a URL or security background.
313 if (mode_ != APP_LAUNCHER) 337 if (mode_ != APP_LAUNCHER)
314 location_entry_->Update(tab_for_state_restoring); 338 location_entry_->Update(tab_for_state_restoring);
315 OnChanged(); 339 OnChanged();
316 } 340 }
317 341
318 void LocationBarView::UpdateContentSettingsIcons() { 342 void LocationBarView::UpdateContentSettingsIcons() {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 void LocationBarView::SetStarToggled(bool on) { 419 void LocationBarView::SetStarToggled(bool on) {
396 if (star_view_) 420 if (star_view_)
397 star_view_->SetToggled(on); 421 star_view_->SetToggled(on);
398 } 422 }
399 423
400 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) { 424 void LocationBarView::ShowStarBubble(const GURL& url, bool newly_bookmarked) {
401 browser::ShowBookmarkBubbleView(star_view_, browser_->profile(), url, 425 browser::ShowBookmarkBubbleView(star_view_, browser_->profile(), url,
402 newly_bookmarked); 426 newly_bookmarked);
403 } 427 }
404 428
429 void LocationBarView::ShowChromeToMobileBubble() {
430 ChromeToMobileServiceFactory::GetForProfile(browser_->profile())->
431 RequestMobileListUpdate();
432 browser::ShowChromeToMobileBubbleView(chrome_to_mobile_view_,
433 browser_->profile());
434 }
435
405 gfx::Point LocationBarView::GetLocationEntryOrigin() const { 436 gfx::Point LocationBarView::GetLocationEntryOrigin() const {
406 gfx::Point origin(location_entry_view_->bounds().origin()); 437 gfx::Point origin(location_entry_view_->bounds().origin());
407 // If the UI layout is RTL, the coordinate system is not transformed and 438 // If the UI layout is RTL, the coordinate system is not transformed and
408 // therefore we need to adjust the X coordinate so that bubble appears on the 439 // therefore we need to adjust the X coordinate so that bubble appears on the
409 // right hand side of the location bar. 440 // right hand side of the location bar.
410 if (base::i18n::IsRTL()) 441 if (base::i18n::IsRTL())
411 origin.set_x(width() - origin.x()); 442 origin.set_x(width() - origin.x());
412 views::View::ConvertPointToScreen(this, &origin); 443 views::View::ConvertPointToScreen(this, &origin);
413 return origin; 444 return origin;
414 } 445 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 // We'll adjust this width and take it out of |entry_width| below. 550 // We'll adjust this width and take it out of |entry_width| below.
520 } else { 551 } else {
521 location_icon_view_->SetVisible(true); 552 location_icon_view_->SetVisible(true);
522 location_icon_width = location_icon_view_->GetPreferredSize().width(); 553 location_icon_width = location_icon_view_->GetPreferredSize().width();
523 entry_width -= (kEdgeThickness + kEdgeItemPadding + location_icon_width + 554 entry_width -= (kEdgeThickness + kEdgeItemPadding + location_icon_width +
524 kItemEditPadding); 555 kItemEditPadding);
525 } 556 }
526 557
527 if (star_view_ && star_view_->visible()) 558 if (star_view_ && star_view_->visible())
528 entry_width -= star_view_->GetPreferredSize().width() + kItemPadding; 559 entry_width -= star_view_->GetPreferredSize().width() + kItemPadding;
560 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible())
561 entry_width -= chrome_to_mobile_view_->GetPreferredSize().width() +
562 kItemPadding;
529 for (PageActionViews::const_iterator i(page_action_views_.begin()); 563 for (PageActionViews::const_iterator i(page_action_views_.begin());
530 i != page_action_views_.end(); ++i) { 564 i != page_action_views_.end(); ++i) {
531 if ((*i)->visible()) 565 if ((*i)->visible())
532 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); 566 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding);
533 } 567 }
534 for (ContentSettingViews::const_iterator i(content_setting_views_.begin()); 568 for (ContentSettingViews::const_iterator i(content_setting_views_.begin());
535 i != content_setting_views_.end(); ++i) { 569 i != content_setting_views_.end(); ++i) {
536 if ((*i)->visible()) 570 if ((*i)->visible())
537 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding); 571 entry_width -= ((*i)->GetPreferredSize().width() + kItemPadding);
538 } 572 }
539 // The gap between the edit and whatever is to its right is shortened. 573 // The gap between the edit and whatever is to its right is shortened.
540 entry_width += kEditInternalSpace; 574 entry_width += kEditInternalSpace;
541 575
542 // Size the EV bubble. We do this after taking the star/page actions/content 576 // Size the EV bubble after taking star/ChromeToMobile/page actions/content
543 // settings out of |entry_width| so we won't take too much space. 577 // settings out of |entry_width| so we won't take too much space.
544 if (ev_bubble_width) { 578 if (ev_bubble_width) {
545 // Try to elide the bubble to be no larger than half the total available 579 // Try to elide the bubble to be no larger than half the total available
546 // space, but never elide it any smaller than 150 px. 580 // space, but never elide it any smaller than 150 px.
547 static const int kMinElidedBubbleWidth = 150; 581 static const int kMinElidedBubbleWidth = 150;
548 static const double kMaxBubbleFraction = 0.5; 582 static const double kMaxBubbleFraction = 0.5;
549 const int total_padding = 583 const int total_padding =
550 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding; 584 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding;
551 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, 585 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth,
552 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); 586 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction)));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 620
587 // Lay out items to the right of the edit field. 621 // Lay out items to the right of the edit field.
588 int offset = width() - kEdgeThickness - kEdgeItemPadding; 622 int offset = width() - kEdgeThickness - kEdgeItemPadding;
589 if (star_view_ && star_view_->visible()) { 623 if (star_view_ && star_view_->visible()) {
590 int star_width = star_view_->GetPreferredSize().width(); 624 int star_width = star_view_->GetPreferredSize().width();
591 offset -= star_width; 625 offset -= star_width;
592 star_view_->SetBounds(offset, location_y, star_width, location_height); 626 star_view_->SetBounds(offset, location_y, star_width, location_height);
593 offset -= kItemPadding; 627 offset -= kItemPadding;
594 } 628 }
595 629
630 if (chrome_to_mobile_view_ && chrome_to_mobile_view_->visible()) {
631 int icon_width = chrome_to_mobile_view_->GetPreferredSize().width();
632 offset -= icon_width;
633 chrome_to_mobile_view_->SetBounds(offset, location_y,
634 icon_width, location_height);
635 offset -= kItemPadding;
636 }
637
596 for (PageActionViews::const_iterator i(page_action_views_.begin()); 638 for (PageActionViews::const_iterator i(page_action_views_.begin());
597 i != page_action_views_.end(); ++i) { 639 i != page_action_views_.end(); ++i) {
598 if ((*i)->visible()) { 640 if ((*i)->visible()) {
599 int page_action_width = (*i)->GetPreferredSize().width(); 641 int page_action_width = (*i)->GetPreferredSize().width();
600 offset -= page_action_width; 642 offset -= page_action_width;
601 (*i)->SetBounds(offset, location_y, page_action_width, location_height); 643 (*i)->SetBounds(offset, location_y, page_action_width, location_height);
602 offset -= kItemPadding; 644 offset -= kItemPadding;
603 } 645 }
604 } 646 }
605 // We use a reverse_iterator here because we're laying out the views from 647 // We use a reverse_iterator here because we're laying out the views from
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 if ((*it)->page_action()) 993 if ((*it)->page_action())
952 page_actions.push_back((*it)->page_action()); 994 page_actions.push_back((*it)->page_action());
953 } 995 }
954 996
955 // On startup we sometimes haven't loaded any extensions. This makes sure 997 // On startup we sometimes haven't loaded any extensions. This makes sure
956 // we catch up when the extensions (and any page actions) load. 998 // we catch up when the extensions (and any page actions) load.
957 if (page_actions.size() != page_action_views_.size()) { 999 if (page_actions.size() != page_action_views_.size()) {
958 DeletePageActionViews(); // Delete the old views (if any). 1000 DeletePageActionViews(); // Delete the old views (if any).
959 1001
960 page_action_views_.resize(page_actions.size()); 1002 page_action_views_.resize(page_actions.size());
1003 View* view = chrome_to_mobile_view_ ? chrome_to_mobile_view_ :
1004 static_cast<View*>(star_view_);
961 1005
962 // Add the page actions in reverse order, so that the child views are 1006 // Add the page actions in reverse order, so that the child views are
963 // inserted in left-to-right order for accessibility. 1007 // inserted in left-to-right order for accessibility.
964 for (int i = page_actions.size() - 1; i >= 0; --i) { 1008 for (int i = page_actions.size() - 1; i >= 0; --i) {
965 page_action_views_[i] = new PageActionWithBadgeView( 1009 page_action_views_[i] = new PageActionWithBadgeView(
966 new PageActionImageView(this, page_actions[i])); 1010 new PageActionImageView(this, page_actions[i]));
967 page_action_views_[i]->SetVisible(false); 1011 page_action_views_[i]->SetVisible(false);
968 AddChildViewAt(page_action_views_[i], GetIndexOf(star_view_)); 1012 AddChildViewAt(page_action_views_[i], GetIndexOf(view));
969 } 1013 }
970 } 1014 }
971 1015
972 WebContents* contents = GetWebContentsFromDelegate(delegate_); 1016 WebContents* contents = GetWebContentsFromDelegate(delegate_);
973 if (!page_action_views_.empty() && contents) { 1017 if (!page_action_views_.empty() && contents) {
974 GURL url = GURL(model_->GetText()); 1018 GURL url = GURL(model_->GetText());
975 1019
976 for (PageActionViews::const_iterator i(page_action_views_.begin()); 1020 for (PageActionViews::const_iterator i(page_action_views_.begin());
977 i != page_action_views_.end(); ++i) { 1021 i != page_action_views_.end(); ++i) {
978 (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents, 1022 (*i)->UpdateVisibility(model_->input_in_progress() ? NULL : contents,
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 !suggested_text_view_->GetText().empty(); 1280 !suggested_text_view_->GetText().empty();
1237 } 1281 }
1238 1282
1239 #if !defined(USE_AURA) 1283 #if !defined(USE_AURA)
1240 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { 1284 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() {
1241 CHECK(!views::Widget::IsPureViews()); 1285 CHECK(!views::Widget::IsPureViews());
1242 return static_cast<OmniboxViewWin*>(location_entry_.get()); 1286 return static_cast<OmniboxViewWin*>(location_entry_.get());
1243 } 1287 }
1244 #endif 1288 #endif
1245 #endif 1289 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698