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

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

Issue 7206055: Add an option to run Chrome in the views desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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
(...skipping 17 matching lines...) Expand all
28 #include "chrome/browser/ui/view_ids.h" 28 #include "chrome/browser/ui/view_ids.h"
29 #include "chrome/browser/ui/views/browser_dialogs.h" 29 #include "chrome/browser/ui/views/browser_dialogs.h"
30 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" 30 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
31 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h" 31 #include "chrome/browser/ui/views/location_bar/ev_bubble_view.h"
32 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" 32 #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
33 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 33 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
34 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h" 34 #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
35 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" 35 #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h"
36 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" 36 #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h"
37 #include "chrome/browser/ui/views/location_bar/star_view.h" 37 #include "chrome/browser/ui/views/location_bar/star_view.h"
38 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"
38 #include "chrome/common/chrome_switches.h" 39 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
40 #include "content/browser/renderer_host/render_widget_host_view.h" 41 #include "content/browser/renderer_host/render_widget_host_view.h"
41 #include "content/common/notification_service.h" 42 #include "content/common/notification_service.h"
42 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
43 #include "grit/theme_resources.h" 44 #include "grit/theme_resources.h"
44 #include "grit/theme_resources_standard.h" 45 #include "grit/theme_resources_standard.h"
45 #include "ui/base/accessibility/accessible_view_state.h" 46 #include "ui/base/accessibility/accessible_view_state.h"
46 #include "ui/base/dragdrop/drag_drop_types.h" 47 #include "ui/base/dragdrop/drag_drop_types.h"
47 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
48 #include "ui/base/resource/resource_bundle.h" 49 #include "ui/base/resource/resource_bundle.h"
49 #include "ui/base/theme_provider.h" 50 #include "ui/base/theme_provider.h"
50 #include "ui/gfx/canvas_skia.h" 51 #include "ui/gfx/canvas_skia.h"
51 #include "ui/gfx/color_utils.h" 52 #include "ui/gfx/color_utils.h"
52 #include "ui/gfx/skia_util.h" 53 #include "ui/gfx/skia_util.h"
53 #include "views/controls/label.h" 54 #include "views/controls/label.h"
55 #include "views/controls/textfield/native_textfield_views.h"
54 #include "views/drag_utils.h" 56 #include "views/drag_utils.h"
55 57
56 #if defined(OS_WIN) 58 #if defined(OS_WIN)
57 #include "chrome/browser/ui/views/first_run_bubble.h" 59 #include "chrome/browser/ui/views/first_run_bubble.h"
58 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" 60 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h"
59 #endif 61 #endif
60 62
61 using views::View; 63 using views::View;
62 64
63 namespace { 65 namespace {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 ev_bubble_view_ = 166 ev_bubble_view_ =
165 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID, 167 new EVBubbleView(kEVBubbleBackgroundImages, IDR_OMNIBOX_HTTPS_VALID,
166 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this); 168 GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), this);
167 AddChildView(ev_bubble_view_); 169 AddChildView(ev_bubble_view_);
168 ev_bubble_view_->SetVisible(false); 170 ev_bubble_view_->SetVisible(false);
169 ev_bubble_view_->SetDragController(this); 171 ev_bubble_view_->SetDragController(this);
170 172
171 // URL edit field. 173 // URL edit field.
172 // View container for URL edit field. 174 // View container for URL edit field.
173 #if defined(OS_WIN) 175 #if defined(OS_WIN)
174 location_entry_.reset(new OmniboxViewWin(font_, this, model_, this, 176 if (UseViewsOmnibox()) {
175 GetWidget()->GetNativeView(), profile_, browser_->command_updater(), 177 OmniboxViewViews* omnibox_view =
176 mode_ == POPUP, this)); 178 new OmniboxViewViews(this, model_, profile_,
179 browser_->command_updater(), mode_ == POPUP, this);
180 omnibox_view->Init();
181 location_entry_.reset(omnibox_view);
182 } else {
183 location_entry_.reset(new OmniboxViewWin(font_, this, model_, this,
184 GetWidget()->GetNativeView(), profile_, browser_->command_updater(),
185 mode_ == POPUP, this));
186 }
177 #else 187 #else
178 location_entry_.reset(OmniboxViewGtk::Create(this, model_, profile_, 188 location_entry_.reset(OmniboxViewGtk::Create(this, model_, profile_,
179 browser_->command_updater(), mode_ == POPUP, this)); 189 browser_->command_updater(), mode_ == POPUP, this));
180 #endif 190 #endif
181 191
182 location_entry_view_ = location_entry_->AddToView(this); 192 location_entry_view_ = location_entry_->AddToView(this);
183 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); 193 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE);
184 194
185 selected_keyword_view_ = new SelectedKeywordView( 195 selected_keyword_view_ = new SelectedKeywordView(
186 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, 196 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 bool animate_to_complete) { 424 bool animate_to_complete) {
415 // Don't show the suggested text if inline autocomplete is prevented. 425 // Don't show the suggested text if inline autocomplete is prevented.
416 if (!text.empty()) { 426 if (!text.empty()) {
417 if (!suggested_text_view_) { 427 if (!suggested_text_view_) {
418 suggested_text_view_ = new SuggestedTextView(location_entry_->model()); 428 suggested_text_view_ = new SuggestedTextView(location_entry_->model());
419 suggested_text_view_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 429 suggested_text_view_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
420 suggested_text_view_->SetColor( 430 suggested_text_view_->SetColor(
421 GetColor(ToolbarModel::NONE, 431 GetColor(ToolbarModel::NONE,
422 LocationBarView::DEEMPHASIZED_TEXT)); 432 LocationBarView::DEEMPHASIZED_TEXT));
423 suggested_text_view_->SetText(UTF16ToWide(text)); 433 suggested_text_view_->SetText(UTF16ToWide(text));
424 suggested_text_view_->SetFont(location_entry_->GetFont()); 434 if (!UseViewsOmnibox())
435 suggested_text_view_->SetFont(GetOmniboxViewWin()->GetFont());
425 AddChildView(suggested_text_view_); 436 AddChildView(suggested_text_view_);
426 } else if (suggested_text_view_->GetText() != UTF16ToWide(text)) { 437 } else if (suggested_text_view_->GetText() != UTF16ToWide(text)) {
427 suggested_text_view_->SetText(UTF16ToWide(text)); 438 suggested_text_view_->SetText(UTF16ToWide(text));
428 } 439 }
429 if (animate_to_complete && !location_entry_->IsImeComposing()) 440 if (animate_to_complete && !location_entry_->IsImeComposing())
430 suggested_text_view_->StartAnimation(); 441 suggested_text_view_->StartAnimation();
431 } else if (suggested_text_view_) { 442 } else if (suggested_text_view_) {
432 delete suggested_text_view_; 443 delete suggested_text_view_;
433 suggested_text_view_ = NULL; 444 suggested_text_view_ = NULL;
434 } else { 445 } else {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 static const int kMinElidedBubbleWidth = 150; 537 static const int kMinElidedBubbleWidth = 150;
527 static const double kMaxBubbleFraction = 0.5; 538 static const double kMaxBubbleFraction = 0.5;
528 const int total_padding = 539 const int total_padding =
529 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding; 540 kEdgeThickness + kBubbleHorizontalPadding + kItemEditPadding;
530 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth, 541 ev_bubble_width = std::min(ev_bubble_width, std::max(kMinElidedBubbleWidth,
531 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction))); 542 static_cast<int>((entry_width - total_padding) * kMaxBubbleFraction)));
532 entry_width -= (total_padding + ev_bubble_width); 543 entry_width -= (total_padding + ev_bubble_width);
533 } 544 }
534 545
535 #if defined(OS_WIN) 546 #if defined(OS_WIN)
536 RECT formatting_rect; 547 int max_edit_width = entry_width;
537 location_entry_->GetRect(&formatting_rect); 548 if (!UseViewsOmnibox()) {
538 RECT edit_bounds; 549 RECT formatting_rect;
539 location_entry_->GetClientRect(&edit_bounds); 550 GetOmniboxViewWin()->GetRect(&formatting_rect);
540 int max_edit_width = entry_width - formatting_rect.left - 551 RECT edit_bounds;
541 (edit_bounds.right - formatting_rect.right); 552 GetOmniboxViewWin()->GetClientRect(&edit_bounds);
553 max_edit_width = entry_width - formatting_rect.left -
554 (edit_bounds.right - formatting_rect.right);
555 }
542 #else 556 #else
543 int max_edit_width = entry_width; 557 int max_edit_width = entry_width;
544 #endif 558 #endif
545 559
546 if (max_edit_width < 0) 560 if (max_edit_width < 0)
547 return; 561 return;
548 const int available_width = AvailableWidth(max_edit_width); 562 const int available_width = AvailableWidth(max_edit_width);
549 563
550 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; 564 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
551 selected_keyword_view_->SetVisible(show_selected_keyword); 565 selected_keyword_view_->SetVisible(show_selected_keyword);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 // Layout out the suggested text view right aligned to the location 663 // Layout out the suggested text view right aligned to the location
650 // entry. Only show the suggested text if we can fit the text from one 664 // entry. Only show the suggested text if we can fit the text from one
651 // character before the end of the selection to the end of the text and the 665 // character before the end of the selection to the end of the text and the
652 // suggested text. If we can't it means either the suggested text is too big, 666 // suggested text. If we can't it means either the suggested text is too big,
653 // or the user has scrolled. 667 // or the user has scrolled.
654 668
655 // TODO(sky): We could potentially combine this with the previous step to 669 // TODO(sky): We could potentially combine this with the previous step to
656 // force using minimum size if necessary, but currently the chance of showing 670 // force using minimum size if necessary, but currently the chance of showing
657 // keyword hints and suggested text is minimal and we're not confident this 671 // keyword hints and suggested text is minimal and we're not confident this
658 // is the right approach for suggested text. 672 // is the right approach for suggested text.
659 if (suggested_text_view_) { 673 if (suggested_text_view_ && !UseViewsOmnibox()) {
sky 2011/06/21 21:52:11 Do we need a NOTIMPLEMENTED for the UseViewsOmnibo
660 // TODO(sky): need to layout when the user changes caret position. 674 // TODO(sky): need to layout when the user changes caret position.
661 int suggested_text_width = suggested_text_view_->GetPreferredSize().width(); 675 int suggested_text_width = suggested_text_view_->GetPreferredSize().width();
662 int vis_text_width = location_entry_->WidthOfTextAfterCursor(); 676 int vis_text_width = GetOmniboxViewWin()->WidthOfTextAfterCursor();
663 if (vis_text_width + suggested_text_width > entry_width) { 677 if (vis_text_width + suggested_text_width > entry_width) {
664 // Hide the suggested text if the user has scrolled or we can't fit all 678 // Hide the suggested text if the user has scrolled or we can't fit all
665 // the suggested text. 679 // the suggested text.
666 suggested_text_view_->SetBounds(0, 0, 0, 0); 680 suggested_text_view_->SetBounds(0, 0, 0, 0);
667 } else { 681 } else {
668 int location_needed_width = location_entry_->TextWidth(); 682 int location_needed_width = location_entry_->TextWidth();
669 location_bounds.set_width(std::min(location_needed_width, 683 location_bounds.set_width(std::min(location_needed_width,
670 entry_width - suggested_text_width)); 684 entry_width - suggested_text_width));
671 // TODO(sky): figure out why this needs the -1. 685 // TODO(sky): figure out why this needs the -1.
672 suggested_text_view_->SetBounds(location_bounds.right() - 1, 686 suggested_text_view_->SetBounds(location_bounds.right() - 1,
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 } else if (event.IsRightMouseButton()) { 785 } else if (event.IsRightMouseButton()) {
772 msg = WM_RBUTTONUP; 786 msg = WM_RBUTTONUP;
773 } else { 787 } else {
774 NOTREACHED(); 788 NOTREACHED();
775 return; 789 return;
776 } 790 }
777 OnMouseEvent(event, msg); 791 OnMouseEvent(event, msg);
778 } 792 }
779 793
780 void LocationBarView::OnMouseCaptureLost() { 794 void LocationBarView::OnMouseCaptureLost() {
781 location_entry_->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); 795 if (!UseViewsOmnibox())
796 GetOmniboxViewWin()->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint());
782 } 797 }
783 #endif 798 #endif
784 799
785 void LocationBarView::OnAutocompleteAccept( 800 void LocationBarView::OnAutocompleteAccept(
786 const GURL& url, 801 const GURL& url,
787 WindowOpenDisposition disposition, 802 WindowOpenDisposition disposition,
788 PageTransition::Type transition, 803 PageTransition::Type transition,
789 const GURL& alternate_nav_url) { 804 const GURL& alternate_nav_url) {
790 // WARNING: don't add an early return here. The calls after the if must 805 // WARNING: don't add an early return here. The calls after the if must
791 // happen. 806 // happen.
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 } 979 }
965 } 980 }
966 } 981 }
967 } 982 }
968 983
969 #if defined(OS_WIN) 984 #if defined(OS_WIN)
970 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) { 985 void LocationBarView::OnMouseEvent(const views::MouseEvent& event, UINT msg) {
971 UINT flags = event.GetWindowsFlags(); 986 UINT flags = event.GetWindowsFlags();
972 gfx::Point screen_point(event.location()); 987 gfx::Point screen_point(event.location());
973 ConvertPointToScreen(this, &screen_point); 988 ConvertPointToScreen(this, &screen_point);
974 location_entry_->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); 989 if (!UseViewsOmnibox())
990 GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT());
975 } 991 }
976 #endif 992 #endif
977 993
978 void LocationBarView::ShowFirstRunBubbleInternal( 994 void LocationBarView::ShowFirstRunBubbleInternal(
979 FirstRun::BubbleType bubble_type) { 995 FirstRun::BubbleType bubble_type) {
980 #if defined(OS_WIN) // First run bubble doesn't make sense for Chrome OS. 996 #if defined(OS_WIN) // First run bubble doesn't make sense for Chrome OS.
981 // Point at the start of the edit control; adjust to look as good as possible. 997 // Point at the start of the edit control; adjust to look as good as possible.
982 const int kXOffset = kNormalHorizontalEdgeThickness + kEdgeItemPadding + 998 const int kXOffset = kNormalHorizontalEdgeThickness + kEdgeItemPadding +
983 ResourceBundle::GetSharedInstance().GetBitmapNamed( 999 ResourceBundle::GetSharedInstance().GetBitmapNamed(
984 IDR_OMNIBOX_HTTP)->width() + kItemPadding; 1000 IDR_OMNIBOX_HTTP)->width() + kItemPadding;
(...skipping 11 matching lines...) Expand all
996 #endif 1012 #endif
997 } 1013 }
998 1014
999 std::string LocationBarView::GetClassName() const { 1015 std::string LocationBarView::GetClassName() const {
1000 return kViewClassName; 1016 return kViewClassName;
1001 } 1017 }
1002 1018
1003 bool LocationBarView::SkipDefaultKeyEventProcessing( 1019 bool LocationBarView::SkipDefaultKeyEventProcessing(
1004 const views::KeyEvent& event) { 1020 const views::KeyEvent& event) {
1005 #if defined(OS_WIN) 1021 #if defined(OS_WIN)
1022 bool views_omnibox = UseViewsOmnibox();
1006 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { 1023 if (views::FocusManager::IsTabTraversalKeyEvent(event)) {
1007 if (HasValidSuggestText()) { 1024 if (HasValidSuggestText()) {
1008 // Return true so that the edit sees the tab and commits the suggestion. 1025 // Return true so that the edit sees the tab and commits the suggestion.
1009 return true; 1026 return true;
1010 } 1027 }
1011 if (keyword_hint_view_->IsVisible() && !event.IsShiftDown()) { 1028 if (keyword_hint_view_->IsVisible() && !event.IsShiftDown()) {
1012 // Return true so the edit gets the tab event and enters keyword mode. 1029 // Return true so the edit gets the tab event and enters keyword mode.
1013 return true; 1030 return true;
1014 } 1031 }
1015 1032
1016 // If the caret is not at the end, then tab moves the caret to the end. 1033 // If the caret is not at the end, then tab moves the caret to the end.
1017 if (!location_entry_->IsCaretAtEnd()) 1034 if (!views_omnibox && !GetOmniboxViewWin()->IsCaretAtEnd())
1018 return true; 1035 return true;
1019 1036
1020 // Tab while showing instant commits instant immediately. 1037 // Tab while showing instant commits instant immediately.
1021 // Return true so that focus traversal isn't attempted. The edit ends 1038 // Return true so that focus traversal isn't attempted. The edit ends
1022 // up doing nothing in this case. 1039 // up doing nothing in this case.
1023 if (location_entry_->model()->AcceptCurrentInstantPreview()) 1040 if (location_entry_->model()->AcceptCurrentInstantPreview())
1024 return true; 1041 return true;
1025 } 1042 }
1026 1043
1027 return location_entry_->SkipDefaultKeyEventProcessing(event); 1044 if (!views_omnibox)
1045 return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event);
1046 return false;
1028 #else 1047 #else
1029 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in 1048 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in
1030 // src/views/focus/focus_manager.cc for details. 1049 // src/views/focus/focus_manager.cc for details.
1031 return false; 1050 return false;
1032 #endif 1051 #endif
1033 } 1052 }
1034 1053
1035 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) { 1054 void LocationBarView::GetAccessibleState(ui::AccessibleViewState* state) {
1036 state->role = ui::AccessibilityTypes::ROLE_GROUPING; 1055 state->role = ui::AccessibilityTypes::ROLE_GROUPING;
1037 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION); 1056 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_LOCATION);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 if (*name == prefs::kEditBookmarksEnabled) 1233 if (*name == prefs::kEditBookmarksEnabled)
1215 Update(NULL); 1234 Update(NULL);
1216 } 1235 }
1217 } 1236 }
1218 1237
1219 #if defined(OS_WIN) 1238 #if defined(OS_WIN)
1220 bool LocationBarView::HasValidSuggestText() const { 1239 bool LocationBarView::HasValidSuggestText() const {
1221 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1240 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1222 !suggested_text_view_->GetText().empty(); 1241 !suggested_text_view_->GetText().empty();
1223 } 1242 }
1243
1244 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() {
oshima 2011/06/21 22:36:07 Looks like this shouldn't return NULL. maybe CHEC
1245 return UseViewsOmnibox() ? NULL :
1246 static_cast<OmniboxViewWin*>(location_entry_.get());
1247 }
1248
1249 // Returns true if the views-based omnibox should be used. When false,
sky 2011/06/21 21:52:11 remove comment as its in the header.
1250 // |location_entry_| can be cast to OmniboxViewWin.
1251 // static
1252 bool LocationBarView::UseViewsOmnibox() {
1253 return views::Widget::IsPureViews() ||
1254 views::NativeTextfieldViews::IsTextfieldViewsEnabled();
1255 }
1224 #endif 1256 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698