Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 #include "ui/base/accessibility/accessible_view_state.h" | 50 #include "ui/base/accessibility/accessible_view_state.h" |
| 51 #include "ui/base/dragdrop/drag_drop_types.h" | 51 #include "ui/base/dragdrop/drag_drop_types.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "ui/base/resource/resource_bundle.h" | 53 #include "ui/base/resource/resource_bundle.h" |
| 54 #include "ui/base/theme_provider.h" | 54 #include "ui/base/theme_provider.h" |
| 55 #include "ui/gfx/canvas_skia.h" | 55 #include "ui/gfx/canvas_skia.h" |
| 56 #include "ui/gfx/color_utils.h" | 56 #include "ui/gfx/color_utils.h" |
| 57 #include "ui/gfx/image/image.h" | 57 #include "ui/gfx/image/image.h" |
| 58 #include "ui/gfx/skia_util.h" | 58 #include "ui/gfx/skia_util.h" |
| 59 #include "ui/views/controls/label.h" | 59 #include "ui/views/controls/label.h" |
| 60 #include "ui/views/controls/textfield/native_textfield_views.h" | |
| 61 #include "ui/views/drag_utils.h" | 60 #include "ui/views/drag_utils.h" |
| 62 | 61 |
| 63 #if !defined(OS_CHROMEOS) | 62 #if !defined(OS_CHROMEOS) |
| 64 #include "chrome/browser/ui/views/first_run_bubble.h" | 63 #include "chrome/browser/ui/views/first_run_bubble.h" |
| 65 #endif | 64 #endif |
| 66 | 65 |
| 67 #if defined(OS_WIN) || defined(USE_AURA) | 66 #if defined(OS_WIN) || defined(USE_AURA) |
| 68 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" | 67 #include "chrome/browser/ui/views/location_bar/suggested_text_view.h" |
| 69 #endif | 68 #endif |
| 70 | 69 |
| 71 using views::View; | 70 using views::View; |
| 72 | 71 |
| 73 namespace { | 72 namespace { |
| 74 | 73 |
| 75 TabContents* GetTabContentsFromDelegate(LocationBarView::Delegate* delegate) { | 74 TabContents* GetTabContentsFromDelegate(LocationBarView::Delegate* delegate) { |
| 76 const TabContentsWrapper* wrapper = delegate->GetTabContentsWrapper(); | 75 const TabContentsWrapper* wrapper = delegate->GetTabContentsWrapper(); |
| 77 return wrapper ? wrapper->tab_contents() : NULL; | 76 return wrapper ? wrapper->tab_contents() : NULL; |
| 78 } | 77 } |
| 79 | 78 |
| 79 // A utility function to cast OmniboxView to OmniboxViewViews. | |
| 80 OmniboxViewViews* AsViews(OmniboxView* view) { | |
|
alicet1
2011/12/07 22:16:13
is it better as a static conversion method on Omni
oshima
2011/12/08 19:13:01
Only implementation needs this, and I prefer funct
| |
| 81 DCHECK(views::Widget::IsPureViews()); | |
| 82 return static_cast<OmniboxViewViews*>(view); | |
| 83 } | |
| 84 | |
| 80 } // namespace | 85 } // namespace |
| 81 | 86 |
| 82 // static | 87 // static |
| 83 const int LocationBarView::kNormalHorizontalEdgeThickness = 1; | 88 const int LocationBarView::kNormalHorizontalEdgeThickness = 1; |
| 84 const int LocationBarView::kVerticalEdgeThickness = 2; | 89 const int LocationBarView::kVerticalEdgeThickness = 2; |
| 85 const int LocationBarView::kItemPadding = 3; | 90 const int LocationBarView::kItemPadding = 3; |
| 86 const int LocationBarView::kIconInternalPadding = 2; | 91 const int LocationBarView::kIconInternalPadding = 2; |
| 87 const int LocationBarView::kEdgeItemPadding = kItemPadding; | 92 const int LocationBarView::kEdgeItemPadding = kItemPadding; |
| 88 const int LocationBarView::kBubbleHorizontalPadding = 1; | 93 const int LocationBarView::kBubbleHorizontalPadding = 1; |
| 89 const char LocationBarView::kViewClassName[] = | 94 const char LocationBarView::kViewClassName[] = |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 suggested_text_view_(NULL), | 132 suggested_text_view_(NULL), |
| 128 #endif | 133 #endif |
| 129 keyword_hint_view_(NULL), | 134 keyword_hint_view_(NULL), |
| 130 star_view_(NULL), | 135 star_view_(NULL), |
| 131 mode_(mode), | 136 mode_(mode), |
| 132 show_focus_rect_(false), | 137 show_focus_rect_(false), |
| 133 bubble_type_(FirstRun::MINIMAL_BUBBLE), | 138 bubble_type_(FirstRun::MINIMAL_BUBBLE), |
| 134 template_url_service_(NULL), | 139 template_url_service_(NULL), |
| 135 animation_offset_(0) { | 140 animation_offset_(0) { |
| 136 set_id(VIEW_ID_LOCATION_BAR); | 141 set_id(VIEW_ID_LOCATION_BAR); |
| 137 set_focusable(true); | |
| 138 | 142 |
| 139 if (mode_ == NORMAL) { | 143 if (mode_ == NORMAL) { |
| 140 painter_.reset( | 144 painter_.reset( |
| 141 views::Painter::CreateImagePainter( | 145 views::Painter::CreateImagePainter( |
| 142 *ResourceBundle::GetSharedInstance().GetImageNamed( | 146 *ResourceBundle::GetSharedInstance().GetImageNamed( |
| 143 IDR_LOCATION_BAR_BORDER).ToSkBitmap(), | 147 IDR_LOCATION_BAR_BORDER).ToSkBitmap(), |
| 144 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, | 148 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, |
| 145 kBorderRoundCornerHeight, kBorderRoundCornerWidth), | 149 kBorderRoundCornerHeight, kBorderRoundCornerWidth), |
| 146 true)); | 150 true)); |
| 147 } | 151 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 // URL edit field. | 190 // URL edit field. |
| 187 // View container for URL edit field. | 191 // View container for URL edit field. |
| 188 Profile* profile = browser_->profile(); | 192 Profile* profile = browser_->profile(); |
| 189 location_entry_.reset(OmniboxView::CreateOmniboxView( | 193 location_entry_.reset(OmniboxView::CreateOmniboxView( |
| 190 this, | 194 this, |
| 191 model_, | 195 model_, |
| 192 profile, | 196 profile, |
| 193 browser_->command_updater(), | 197 browser_->command_updater(), |
| 194 mode_ == POPUP, | 198 mode_ == POPUP, |
| 195 this)); | 199 this)); |
| 200 SetOmniboxFocusable(true); | |
| 196 | 201 |
| 197 location_entry_view_ = location_entry_->AddToView(this); | 202 location_entry_view_ = location_entry_->AddToView(this); |
| 198 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); | 203 location_entry_view_->set_id(VIEW_ID_AUTOCOMPLETE); |
| 199 | 204 |
| 200 selected_keyword_view_ = new SelectedKeywordView( | 205 selected_keyword_view_ = new SelectedKeywordView( |
| 201 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, | 206 kSelectedKeywordBackgroundImages, IDR_KEYWORD_SEARCH_MAGNIFIER, |
| 202 GetColor(ToolbarModel::NONE, TEXT), profile); | 207 GetColor(ToolbarModel::NONE, TEXT), profile); |
| 203 AddChildView(selected_keyword_view_); | 208 AddChildView(selected_keyword_view_); |
| 204 selected_keyword_view_->SetFont(font_); | 209 selected_keyword_view_->SetFont(font_); |
| 205 selected_keyword_view_->SetVisible(false); | 210 selected_keyword_view_->SetVisible(false); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 | 442 |
| 438 Layout(); | 443 Layout(); |
| 439 SchedulePaint(); | 444 SchedulePaint(); |
| 440 } | 445 } |
| 441 | 446 |
| 442 string16 LocationBarView::GetInstantSuggestion() const { | 447 string16 LocationBarView::GetInstantSuggestion() const { |
| 443 return HasValidSuggestText() ? suggested_text_view_->GetText() : string16(); | 448 return HasValidSuggestText() ? suggested_text_view_->GetText() : string16(); |
| 444 } | 449 } |
| 445 #endif | 450 #endif |
| 446 | 451 |
| 452 void LocationBarView::SetOmniboxFocusable(bool focusable) { | |
| 453 if (views::Widget::IsPureViews()) | |
| 454 AsViews(location_entry_.get())->SetOmniboxFocusable(focusable); | |
| 455 else | |
| 456 set_focusable(focusable); | |
| 457 } | |
| 458 | |
| 459 bool LocationBarView::IsOmniboxFocusableInRootView() const { | |
| 460 return views::Widget::IsPureViews() ? | |
| 461 AsViews(location_entry_.get())->IsOmniboxFocusableInRootView() : | |
| 462 views::View::IsFocusableInRootView(); | |
| 463 } | |
| 464 | |
| 447 gfx::Size LocationBarView::GetPreferredSize() { | 465 gfx::Size LocationBarView::GetPreferredSize() { |
| 448 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? | 466 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? |
| 449 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); | 467 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); |
| 450 } | 468 } |
| 451 | 469 |
| 452 void LocationBarView::Layout() { | 470 void LocationBarView::Layout() { |
| 453 if (!location_entry_.get()) | 471 if (!location_entry_.get()) |
| 454 return; | 472 return; |
| 455 | 473 |
| 456 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. | 474 // TODO(jhawkins): Remove once crbug.com/101994 is fixed. |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1230 !suggested_text_view_->GetText().empty(); | 1248 !suggested_text_view_->GetText().empty(); |
| 1231 } | 1249 } |
| 1232 | 1250 |
| 1233 #if !defined(USE_AURA) | 1251 #if !defined(USE_AURA) |
| 1234 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { | 1252 OmniboxViewWin* LocationBarView::GetOmniboxViewWin() { |
| 1235 CHECK(!views::Widget::IsPureViews()); | 1253 CHECK(!views::Widget::IsPureViews()); |
| 1236 return static_cast<OmniboxViewWin*>(location_entry_.get()); | 1254 return static_cast<OmniboxViewWin*>(location_entry_.get()); |
| 1237 } | 1255 } |
| 1238 #endif | 1256 #endif |
| 1239 #endif | 1257 #endif |
| OLD | NEW |