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

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

Issue 25373009: Translate: New Bubble UX (for the view toolkit) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Bug fix: view id on tests Created 7 years, 1 month 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
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/command_line.h" 10 #include "base/command_line.h"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/app/chrome_command_ids.h" 15 #include "chrome/app/chrome_command_ids.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/command_updater.h" 17 #include "chrome/browser/command_updater.h"
18 #include "chrome/browser/defaults.h" 18 #include "chrome/browser/defaults.h"
19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 19 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
20 #include "chrome/browser/extensions/location_bar_controller.h" 20 #include "chrome/browser/extensions/location_bar_controller.h"
21 #include "chrome/browser/extensions/script_bubble_controller.h" 21 #include "chrome/browser/extensions/script_bubble_controller.h"
22 #include "chrome/browser/extensions/tab_helper.h" 22 #include "chrome/browser/extensions/tab_helper.h"
23 #include "chrome/browser/favicon/favicon_tab_helper.h" 23 #include "chrome/browser/favicon/favicon_tab_helper.h"
24 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/search_engines/template_url.h" 25 #include "chrome/browser/search_engines/template_url.h"
26 #include "chrome/browser/search_engines/template_url_service.h" 26 #include "chrome/browser/search_engines/template_url_service.h"
27 #include "chrome/browser/search_engines/template_url_service_factory.h" 27 #include "chrome/browser/search_engines/template_url_service_factory.h"
28 #include "chrome/browser/translate/translate_tab_helper.h"
28 #include "chrome/browser/ui/browser.h" 29 #include "chrome/browser/ui/browser.h"
29 #include "chrome/browser/ui/browser_finder.h" 30 #include "chrome/browser/ui/browser_finder.h"
30 #include "chrome/browser/ui/browser_instant_controller.h" 31 #include "chrome/browser/ui/browser_instant_controller.h"
31 #include "chrome/browser/ui/browser_window.h" 32 #include "chrome/browser/ui/browser_window.h"
32 #include "chrome/browser/ui/omnibox/location_bar_util.h" 33 #include "chrome/browser/ui/omnibox/location_bar_util.h"
33 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" 34 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
34 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h" 35 #include "chrome/browser/ui/omnibox/omnibox_popup_view.h"
35 #include "chrome/browser/ui/tabs/tab_strip_model.h" 36 #include "chrome/browser/ui/tabs/tab_strip_model.h"
36 #include "chrome/browser/ui/view_ids.h" 37 #include "chrome/browser/ui/view_ids.h"
37 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h" 38 #include "chrome/browser/ui/views/bookmarks/bookmark_prompt_view.h"
38 #include "chrome/browser/ui/views/browser_dialogs.h" 39 #include "chrome/browser/ui/views/browser_dialogs.h"
39 #include "chrome/browser/ui/views/extensions/extension_popup.h" 40 #include "chrome/browser/ui/views/extensions/extension_popup.h"
40 #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"
41 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 42 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
42 #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h" 43 #include "chrome/browser/ui/views/location_bar/generated_credit_card_view.h"
43 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 44 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
44 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h" 45 #include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
45 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 46 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
46 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h" 47 #include "chrome/browser/ui/views/location_bar/open_pdf_in_reader_view.h"
47 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 48 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
48 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 49 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
49 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h" 50 #include "chrome/browser/ui/views/location_bar/script_bubble_icon_view.h"
50 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 51 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
51 #include "chrome/browser/ui/views/location_bar/star_view.h" 52 #include "chrome/browser/ui/views/location_bar/star_view.h"
53 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
52 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 54 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
53 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 55 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
54 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" 56 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
55 #include "chrome/browser/ui/views/omnibox/omnibox_views.h" 57 #include "chrome/browser/ui/views/omnibox/omnibox_views.h"
56 #include "chrome/browser/ui/zoom/zoom_controller.h" 58 #include "chrome/browser/ui/zoom/zoom_controller.h"
59 #include "chrome/common/chrome_switches.h"
57 #include "chrome/common/extensions/feature_switch.h" 60 #include "chrome/common/extensions/feature_switch.h"
58 #include "chrome/common/pref_names.h" 61 #include "chrome/common/pref_names.h"
59 #include "content/public/browser/notification_service.h" 62 #include "content/public/browser/notification_service.h"
60 #include "content/public/browser/render_widget_host_view.h" 63 #include "content/public/browser/render_widget_host_view.h"
61 #include "content/public/browser/web_contents.h" 64 #include "content/public/browser/web_contents.h"
62 #include "grit/generated_resources.h" 65 #include "grit/generated_resources.h"
63 #include "grit/theme_resources.h" 66 #include "grit/theme_resources.h"
64 #include "ui/base/accessibility/accessible_view_state.h" 67 #include "ui/base/accessibility/accessible_view_state.h"
65 #include "ui/base/dragdrop/drag_drop_types.h" 68 #include "ui/base/dragdrop/drag_drop_types.h"
66 #include "ui/base/l10n/l10n_util.h" 69 #include "ui/base/l10n/l10n_util.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 ime_inline_autocomplete_view_(NULL), 178 ime_inline_autocomplete_view_(NULL),
176 selected_keyword_view_(NULL), 179 selected_keyword_view_(NULL),
177 suggested_text_view_(NULL), 180 suggested_text_view_(NULL),
178 keyword_hint_view_(NULL), 181 keyword_hint_view_(NULL),
179 mic_search_view_(NULL), 182 mic_search_view_(NULL),
180 zoom_view_(NULL), 183 zoom_view_(NULL),
181 generated_credit_card_view_(NULL), 184 generated_credit_card_view_(NULL),
182 open_pdf_in_reader_view_(NULL), 185 open_pdf_in_reader_view_(NULL),
183 script_bubble_icon_view_(NULL), 186 script_bubble_icon_view_(NULL),
184 star_view_(NULL), 187 star_view_(NULL),
188 translate_icon_view_(NULL),
185 is_popup_mode_(is_popup_mode), 189 is_popup_mode_(is_popup_mode),
186 show_focus_rect_(false), 190 show_focus_rect_(false),
187 template_url_service_(NULL), 191 template_url_service_(NULL),
188 animation_offset_(0), 192 animation_offset_(0),
189 weak_ptr_factory_(this) { 193 weak_ptr_factory_(this) {
190 if (!views::Textfield::IsViewsTextfieldEnabled()) 194 if (!views::Textfield::IsViewsTextfieldEnabled())
191 set_id(VIEW_ID_OMNIBOX); 195 set_id(VIEW_ID_OMNIBOX);
192 196
193 const int kOmniboxBorderImages[] = IMAGE_GRID(IDR_OMNIBOX_BORDER); 197 const int kOmniboxBorderImages[] = IMAGE_GRID(IDR_OMNIBOX_BORDER);
194 const int kOmniboxPopupImages[] = IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER); 198 const int kOmniboxPopupImages[] = IMAGE_GRID(IDR_OMNIBOX_POPUP_BORDER);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 AddChildView(open_pdf_in_reader_view_); 356 AddChildView(open_pdf_in_reader_view_);
353 357
354 script_bubble_icon_view_ = new ScriptBubbleIconView(delegate()); 358 script_bubble_icon_view_ = new ScriptBubbleIconView(delegate());
355 script_bubble_icon_view_->SetVisible(false); 359 script_bubble_icon_view_->SetVisible(false);
356 AddChildView(script_bubble_icon_view_); 360 AddChildView(script_bubble_icon_view_);
357 361
358 star_view_ = new StarView(command_updater()); 362 star_view_ = new StarView(command_updater());
359 star_view_->SetVisible(false); 363 star_view_->SetVisible(false);
360 AddChildView(star_view_); 364 AddChildView(star_view_);
361 365
366 if (CommandLine::ForCurrentProcess()->HasSwitch(
367 switches::kEnableTranslateNewUX)) {
368 translate_icon_view_ = new TranslateIconView(command_updater());
369 translate_icon_view_->SetVisible(false);
370 AddChildView(translate_icon_view_);
371 }
372
362 registrar_.Add(this, 373 registrar_.Add(this,
363 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED, 374 chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED,
364 content::Source<Profile>(profile_)); 375 content::Source<Profile>(profile_));
365 376
366 // Initialize the location entry. We do this to avoid a black flash which is 377 // Initialize the location entry. We do this to avoid a black flash which is
367 // visible when the location entry has just been initialized. 378 // visible when the location entry has just been initialized.
368 Update(NULL); 379 Update(NULL);
369 } 380 }
370 381
371 bool LocationBarView::IsInitialized() const { 382 bool LocationBarView::IsInitialized() const {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 vertical_edge_thickness(), location_height, 702 vertical_edge_thickness(), location_height,
692 GetBuiltInHorizontalPaddingForChildViews(), 703 GetBuiltInHorizontalPaddingForChildViews(),
693 location_icon_view_); 704 location_icon_view_);
694 } 705 }
695 706
696 if (star_view_ && star_view_->visible()) { 707 if (star_view_ && star_view_->visible()) {
697 trailing_decorations.AddDecoration( 708 trailing_decorations.AddDecoration(
698 vertical_edge_thickness(), location_height, 709 vertical_edge_thickness(), location_height,
699 GetBuiltInHorizontalPaddingForChildViews(), star_view_); 710 GetBuiltInHorizontalPaddingForChildViews(), star_view_);
700 } 711 }
712 if (translate_icon_view_ && translate_icon_view_->visible()) {
713 trailing_decorations.AddDecoration(
714 vertical_edge_thickness(), location_height,
715 GetBuiltInHorizontalPaddingForChildViews(),
716 translate_icon_view_);
717 }
701 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) { 718 if (script_bubble_icon_view_ && script_bubble_icon_view_->visible()) {
702 trailing_decorations.AddDecoration( 719 trailing_decorations.AddDecoration(
703 vertical_edge_thickness(), location_height, 720 vertical_edge_thickness(), location_height,
704 GetBuiltInHorizontalPaddingForChildViews(), 721 GetBuiltInHorizontalPaddingForChildViews(),
705 script_bubble_icon_view_); 722 script_bubble_icon_view_);
706 } 723 }
707 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) { 724 if (open_pdf_in_reader_view_ && open_pdf_in_reader_view_->visible()) {
708 trailing_decorations.AddDecoration( 725 trailing_decorations.AddDecoration(
709 vertical_edge_thickness(), location_height, 726 vertical_edge_thickness(), location_height,
710 GetBuiltInHorizontalPaddingForChildViews(), 727 GetBuiltInHorizontalPaddingForChildViews(),
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 void LocationBarView::Update(const WebContents* contents) { 990 void LocationBarView::Update(const WebContents* contents) {
974 mic_search_view_->SetVisible( 991 mic_search_view_->SetVisible(
975 !GetToolbarModel()->input_in_progress() && browser_ && 992 !GetToolbarModel()->input_in_progress() && browser_ &&
976 browser_->search_model()->voice_search_supported()); 993 browser_->search_model()->voice_search_supported());
977 UpdateContentSettingViewsPreLayout(); 994 UpdateContentSettingViewsPreLayout();
978 generated_credit_card_view_->Update(); 995 generated_credit_card_view_->Update();
979 ZoomBubbleView::CloseBubble(); 996 ZoomBubbleView::CloseBubble();
980 RefreshZoomView(); 997 RefreshZoomView();
981 RefreshPageActionViews(); 998 RefreshPageActionViews();
982 RefreshScriptBubble(); 999 RefreshScriptBubble();
1000 RefreshTranslateIcon();
983 open_pdf_in_reader_view_->Update( 1001 open_pdf_in_reader_view_->Update(
984 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents()); 1002 GetToolbarModel()->input_in_progress() ? NULL : GetWebContents());
985 1003
986 bool star_enabled = browser_defaults::bookmarks_enabled && !is_popup_mode_ && 1004 bool star_enabled = browser_defaults::bookmarks_enabled && !is_popup_mode_ &&
987 star_view_ && !GetToolbarModel()->input_in_progress() && 1005 star_view_ && !GetToolbarModel()->input_in_progress() &&
988 edit_bookmarks_enabled_.GetValue(); 1006 edit_bookmarks_enabled_.GetValue();
989 1007
990 command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled); 1008 command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE, star_enabled);
991 command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR, 1009 command_updater()->UpdateCommandEnabled(IDC_BOOKMARK_PAGE_FROM_STAR,
992 star_enabled); 1010 star_enabled);
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 DCHECK(zoom_view_); 1453 DCHECK(zoom_view_);
1436 WebContents* web_contents = GetWebContents(); 1454 WebContents* web_contents = GetWebContents();
1437 if (!web_contents) 1455 if (!web_contents)
1438 return; 1456 return;
1439 1457
1440 ZoomController* zoom_controller = 1458 ZoomController* zoom_controller =
1441 ZoomController::FromWebContents(web_contents); 1459 ZoomController::FromWebContents(web_contents);
1442 zoom_view_->Update(zoom_controller); 1460 zoom_view_->Update(zoom_controller);
1443 } 1461 }
1444 1462
1463 void LocationBarView::RefreshTranslateIcon() {
1464 if (!translate_icon_view_)
1465 return;
1466
1467 WebContents* web_contents = GetWebContents();
1468 if (!web_contents)
1469 return;
1470
1471 TranslateTabHelper* translate_tab_helper =
1472 TranslateTabHelper::FromWebContents(web_contents);
1473 bool enabled =
1474 translate_tab_helper->language_state().translate_enabled();
1475
1476 command_updater()->UpdateCommandEnabled(IDC_TRANSLATE_PAGE, enabled);
1477 translate_icon_view_->SetVisible(enabled);
1478 }
1479
1445 #if defined(OS_WIN) && !defined(USE_AURA) 1480 #if defined(OS_WIN) && !defined(USE_AURA)
1446 void LocationBarView::OnMouseEvent(const ui::MouseEvent& event, UINT msg) { 1481 void LocationBarView::OnMouseEvent(const ui::MouseEvent& event, UINT msg) {
1447 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get()); 1482 OmniboxViewWin* omnibox_win = GetOmniboxViewWin(location_entry_.get());
1448 if (omnibox_win) { 1483 if (omnibox_win) {
1449 UINT flags = event.native_event().wParam; 1484 UINT flags = event.native_event().wParam;
1450 gfx::Point screen_point(event.location()); 1485 gfx::Point screen_point(event.location());
1451 ConvertPointToScreen(this, &screen_point); 1486 ConvertPointToScreen(this, &screen_point);
1452 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); 1487 omnibox_win->HandleExternalMsg(msg, flags, screen_point.ToPOINT());
1453 } 1488 }
1454 } 1489 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 bounds.Inset(-(horizontal_padding + 1) / 2, 0); 1534 bounds.Inset(-(horizontal_padding + 1) / 2, 0);
1500 location_bar_util::PaintExtensionActionBackground( 1535 location_bar_util::PaintExtensionActionBackground(
1501 *(*page_action_view)->image_view()->page_action(), 1536 *(*page_action_view)->image_view()->page_action(),
1502 tab_id, canvas, bounds, text_color, background_color); 1537 tab_id, canvas, bounds, text_color, background_color);
1503 } 1538 }
1504 } 1539 }
1505 1540
1506 void LocationBarView::AccessibilitySetValue(const string16& new_value) { 1541 void LocationBarView::AccessibilitySetValue(const string16& new_value) {
1507 location_entry_->SetUserText(new_value); 1542 location_entry_->SetUserText(new_value);
1508 } 1543 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/location_bar/star_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698