Chromium Code Reviews| Index: chrome/browser/ui/views/location_bar/location_bar_view.cc |
| =================================================================== |
| --- chrome/browser/ui/views/location_bar/location_bar_view.cc (revision 89828) |
| +++ chrome/browser/ui/views/location_bar/location_bar_view.cc (working copy) |
| @@ -35,6 +35,7 @@ |
| #include "chrome/browser/ui/views/location_bar/page_action_with_badge_view.h" |
| #include "chrome/browser/ui/views/location_bar/selected_keyword_view.h" |
| #include "chrome/browser/ui/views/location_bar/star_view.h" |
| +#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/pref_names.h" |
| #include "content/browser/renderer_host/render_widget_host_view.h" |
| @@ -51,6 +52,7 @@ |
| #include "ui/gfx/color_utils.h" |
| #include "ui/gfx/skia_util.h" |
| #include "views/controls/label.h" |
| +#include "views/controls/textfield/native_textfield_views.h" |
| #include "views/drag_utils.h" |
| #if defined(OS_WIN) |
| @@ -171,9 +173,17 @@ |
| // URL edit field. |
| // View container for URL edit field. |
| #if defined(OS_WIN) |
| - location_entry_.reset(new OmniboxViewWin(font_, this, model_, this, |
| - GetWidget()->GetNativeView(), profile_, browser_->command_updater(), |
| - mode_ == POPUP, this)); |
| + if (UseViewsOmnibox()) { |
| + OmniboxViewViews* omnibox_view = |
| + new OmniboxViewViews(this, model_, profile_, |
| + browser_->command_updater(), mode_ == POPUP, this); |
| + omnibox_view->Init(); |
| + location_entry_.reset(omnibox_view); |
| + } else { |
| + location_entry_.reset(new OmniboxViewWin(font_, this, model_, this, |
| + GetWidget()->GetNativeView(), profile_, browser_->command_updater(), |
| + mode_ == POPUP, this)); |
| + } |
| #else |
| location_entry_.reset(OmniboxViewGtk::Create(this, model_, profile_, |
| browser_->command_updater(), mode_ == POPUP, this)); |
| @@ -421,7 +431,8 @@ |
| GetColor(ToolbarModel::NONE, |
| LocationBarView::DEEMPHASIZED_TEXT)); |
| suggested_text_view_->SetText(UTF16ToWide(text)); |
| - suggested_text_view_->SetFont(location_entry_->GetFont()); |
| + if (!UseViewsOmnibox()) |
| + suggested_text_view_->SetFont(GetOmniboxViewWin()->GetFont()); |
| AddChildView(suggested_text_view_); |
| } else if (suggested_text_view_->GetText() != UTF16ToWide(text)) { |
| suggested_text_view_->SetText(UTF16ToWide(text)); |
| @@ -533,12 +544,15 @@ |
| } |
| #if defined(OS_WIN) |
| - RECT formatting_rect; |
| - location_entry_->GetRect(&formatting_rect); |
| - RECT edit_bounds; |
| - location_entry_->GetClientRect(&edit_bounds); |
| - int max_edit_width = entry_width - formatting_rect.left - |
| - (edit_bounds.right - formatting_rect.right); |
| + int max_edit_width = entry_width; |
| + if (!UseViewsOmnibox()) { |
| + RECT formatting_rect; |
| + GetOmniboxViewWin()->GetRect(&formatting_rect); |
| + RECT edit_bounds; |
| + GetOmniboxViewWin()->GetClientRect(&edit_bounds); |
| + max_edit_width = entry_width - formatting_rect.left - |
| + (edit_bounds.right - formatting_rect.right); |
| + } |
| #else |
| int max_edit_width = entry_width; |
| #endif |
| @@ -656,10 +670,10 @@ |
| // force using minimum size if necessary, but currently the chance of showing |
| // keyword hints and suggested text is minimal and we're not confident this |
| // is the right approach for suggested text. |
| - if (suggested_text_view_) { |
| + if (suggested_text_view_ && !UseViewsOmnibox()) { |
|
sky
2011/06/21 21:52:11
Do we need a NOTIMPLEMENTED for the UseViewsOmnibo
|
| // TODO(sky): need to layout when the user changes caret position. |
| int suggested_text_width = suggested_text_view_->GetPreferredSize().width(); |
| - int vis_text_width = location_entry_->WidthOfTextAfterCursor(); |
| + int vis_text_width = GetOmniboxViewWin()->WidthOfTextAfterCursor(); |
| if (vis_text_width + suggested_text_width > entry_width) { |
| // Hide the suggested text if the user has scrolled or we can't fit all |
| // the suggested text. |
| @@ -778,7 +792,8 @@ |
| } |
| void LocationBarView::OnMouseCaptureLost() { |
| - location_entry_->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); |
| + if (!UseViewsOmnibox()) |
| + GetOmniboxViewWin()->HandleExternalMsg(WM_CAPTURECHANGED, 0, CPoint()); |
| } |
| #endif |
| @@ -971,7 +986,8 @@ |
| UINT flags = event.GetWindowsFlags(); |
| gfx::Point screen_point(event.location()); |
| ConvertPointToScreen(this, &screen_point); |
| - location_entry_->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
| + if (!UseViewsOmnibox()) |
| + GetOmniboxViewWin()->HandleExternalMsg(msg, flags, screen_point.ToPOINT()); |
| } |
| #endif |
| @@ -1003,6 +1019,7 @@ |
| bool LocationBarView::SkipDefaultKeyEventProcessing( |
| const views::KeyEvent& event) { |
| #if defined(OS_WIN) |
| + bool views_omnibox = UseViewsOmnibox(); |
| if (views::FocusManager::IsTabTraversalKeyEvent(event)) { |
| if (HasValidSuggestText()) { |
| // Return true so that the edit sees the tab and commits the suggestion. |
| @@ -1014,7 +1031,7 @@ |
| } |
| // If the caret is not at the end, then tab moves the caret to the end. |
| - if (!location_entry_->IsCaretAtEnd()) |
| + if (!views_omnibox && !GetOmniboxViewWin()->IsCaretAtEnd()) |
| return true; |
| // Tab while showing instant commits instant immediately. |
| @@ -1024,7 +1041,9 @@ |
| return true; |
| } |
| - return location_entry_->SkipDefaultKeyEventProcessing(event); |
| + if (!views_omnibox) |
| + return GetOmniboxViewWin()->SkipDefaultKeyEventProcessing(event); |
| + return false; |
| #else |
| // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in |
| // src/views/focus/focus_manager.cc for details. |
| @@ -1221,4 +1240,17 @@ |
| return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
| !suggested_text_view_->GetText().empty(); |
| } |
| + |
| +OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
|
oshima
2011/06/21 22:36:07
Looks like this shouldn't return NULL.
maybe CHEC
|
| + return UseViewsOmnibox() ? NULL : |
| + static_cast<OmniboxViewWin*>(location_entry_.get()); |
| +} |
| + |
| +// 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.
|
| +// |location_entry_| can be cast to OmniboxViewWin. |
| +// static |
| +bool LocationBarView::UseViewsOmnibox() { |
| + return views::Widget::IsPureViews() || |
| + views::NativeTextfieldViews::IsTextfieldViewsEnabled(); |
| +} |
| #endif |