Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/app/chrome_command_ids.h" | 13 #include "chrome/app/chrome_command_ids.h" |
| 14 #include "chrome/browser/alternate_nav_url_fetcher.h" | 14 #include "chrome/browser/alternate_nav_url_fetcher.h" |
| 15 #include "chrome/browser/chrome_to_mobile_service.h" | 15 #include "chrome/browser/chrome_to_mobile_service.h" |
| 16 #include "chrome/browser/chrome_to_mobile_service_factory.h" | 16 #include "chrome/browser/chrome_to_mobile_service_factory.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/extension_action_util.h" | |
| 19 #include "chrome/browser/extensions/extension_service.h" | 20 #include "chrome/browser/extensions/extension_service.h" |
| 20 #include "chrome/browser/extensions/extension_system.h" | 21 #include "chrome/browser/extensions/extension_system.h" |
| 21 #include "chrome/browser/extensions/location_bar_controller.h" | 22 #include "chrome/browser/extensions/location_bar_controller.h" |
| 22 #include "chrome/browser/extensions/tab_helper.h" | 23 #include "chrome/browser/extensions/tab_helper.h" |
| 23 #include "chrome/browser/favicon/favicon_tab_helper.h" | 24 #include "chrome/browser/favicon/favicon_tab_helper.h" |
| 24 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
| 27 #include "chrome/browser/search_engines/template_url_service.h" | 28 #include "chrome/browser/search_engines/template_url_service.h" |
| 28 #include "chrome/browser/search_engines/template_url_service_factory.h" | 29 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 | 107 |
| 107 // Height of the location bar's round corner region. | 108 // Height of the location bar's round corner region. |
| 108 const int kBorderRoundCornerHeight = 5; | 109 const int kBorderRoundCornerHeight = 5; |
| 109 // Width of location bar's round corner region. | 110 // Width of location bar's round corner region. |
| 110 const int kBorderRoundCornerWidth = 4; | 111 const int kBorderRoundCornerWidth = 4; |
| 111 // Radius of the round corners inside the location bar. | 112 // Radius of the round corners inside the location bar. |
| 112 const int kBorderCornerRadius = 2; | 113 const int kBorderCornerRadius = 2; |
| 113 | 114 |
| 114 const int kDesktopItemPadding = 3; | 115 const int kDesktopItemPadding = 3; |
| 115 const int kDesktopEdgeItemPadding = kDesktopItemPadding; | 116 const int kDesktopEdgeItemPadding = kDesktopItemPadding; |
| 117 const int kDesktopScriptBadgeItemPadding = 9; | |
| 118 const int kDesktopScriptBadgeEdgeItemPadding = kDesktopScriptBadgeItemPadding; | |
| 116 | 119 |
| 117 const int kTouchItemPadding = 8; | 120 const int kTouchItemPadding = 8; |
| 118 const int kTouchEdgeItemPadding = kTouchItemPadding; | 121 const int kTouchEdgeItemPadding = kTouchItemPadding; |
| 119 | 122 |
| 120 // Extra padding for the height of the omnibox in search mode. | 123 // Extra padding for the height of the omnibox in search mode. |
| 121 const int kSearchEditHeightPadding = 2; | 124 const int kSearchEditHeightPadding = 2; |
| 122 | 125 |
| 123 } // namespace | 126 } // namespace |
| 124 | 127 |
| 125 // static | 128 // static |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 | 365 |
| 363 default: | 366 default: |
| 364 NOTREACHED(); | 367 NOTREACHED(); |
| 365 return GetColor(security_level, TEXT); | 368 return GetColor(security_level, TEXT); |
| 366 } | 369 } |
| 367 } | 370 } |
| 368 | 371 |
| 369 // static | 372 // static |
| 370 int LocationBarView::GetItemPadding() { | 373 int LocationBarView::GetItemPadding() { |
| 371 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? | 374 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? |
| 372 kTouchItemPadding : kDesktopItemPadding; | 375 kTouchItemPadding : |
| 376 extensions::switch_utils::AreScriptBadgesEnabled() ? | |
|
Peter Kasting
2012/09/07 22:29:33
Nit: Chrome frowns on nested ?:s (especially witho
Jeffrey Yasskin
2012/09/11 01:16:56
Done. I don't know what we want for touch, but I'd
| |
| 377 kDesktopScriptBadgeItemPadding : kDesktopItemPadding; | |
| 373 } | 378 } |
| 374 | 379 |
| 375 // static | 380 // static |
| 376 int LocationBarView::GetEdgeItemPadding() { | 381 int LocationBarView::GetEdgeItemPadding() { |
| 377 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? | 382 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? |
| 378 kTouchEdgeItemPadding : kDesktopEdgeItemPadding; | 383 kTouchEdgeItemPadding : |
| 384 extensions::switch_utils::AreScriptBadgesEnabled() ? | |
| 385 kDesktopScriptBadgeEdgeItemPadding : kDesktopEdgeItemPadding; | |
| 379 } | 386 } |
| 380 | 387 |
| 381 // DropdownBarHostDelegate | 388 // DropdownBarHostDelegate |
| 382 void LocationBarView::SetFocusAndSelection(bool select_all) { | 389 void LocationBarView::SetFocusAndSelection(bool select_all) { |
| 383 FocusLocation(select_all); | 390 FocusLocation(select_all); |
| 384 } | 391 } |
| 385 | 392 |
| 386 void LocationBarView::SetAnimationOffset(int offset) { | 393 void LocationBarView::SetAnimationOffset(int offset) { |
| 387 animation_offset_ = offset; | 394 animation_offset_ = offset; |
| 388 } | 395 } |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 paint.setStyle(SkPaint::kFill_Style); | 911 paint.setStyle(SkPaint::kFill_Style); |
| 905 paint.setAntiAlias(true); | 912 paint.setAntiAlias(true); |
| 906 // TODO(jamescook): Make the corners of the dropdown match the corners of | 913 // TODO(jamescook): Make the corners of the dropdown match the corners of |
| 907 // the omnibox. | 914 // the omnibox. |
| 908 const SkScalar radius(SkIntToScalar(kBorderCornerRadius)); | 915 const SkScalar radius(SkIntToScalar(kBorderCornerRadius)); |
| 909 bounds.Inset(kNormalHorizontalEdgeThickness, 0); | 916 bounds.Inset(kNormalHorizontalEdgeThickness, 0); |
| 910 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, | 917 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, |
| 911 radius, paint); | 918 radius, paint); |
| 912 if (action_box_button_view_) | 919 if (action_box_button_view_) |
| 913 PaintActionBoxBackground(canvas, bounds); | 920 PaintActionBoxBackground(canvas, bounds); |
| 921 PaintPageActionBackgrounds(canvas); | |
| 914 } else { | 922 } else { |
| 915 canvas->FillRect(bounds, color); | 923 canvas->FillRect(bounds, color); |
| 916 } | 924 } |
| 917 | 925 |
| 918 if (show_focus_rect_ && HasFocus()) { | 926 if (show_focus_rect_ && HasFocus()) { |
| 919 gfx::Rect r = location_entry_view_->bounds(); | 927 gfx::Rect r = location_entry_view_->bounds(); |
| 920 // TODO(jamescook): Is this still needed? | 928 // TODO(jamescook): Is this still needed? |
| 921 #if defined(OS_WIN) | 929 #if defined(OS_WIN) |
| 922 r.Inset(-1, -1); | 930 r.Inset(-1, -1); |
| 923 #else | 931 #else |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1208 bounds.set_width(kBorderCornerRadius); | 1216 bounds.set_width(kBorderCornerRadius); |
| 1209 canvas->DrawRect(bounds, paint); | 1217 canvas->DrawRect(bounds, paint); |
| 1210 | 1218 |
| 1211 // Draw left border. | 1219 // Draw left border. |
| 1212 gfx::Point line_end(bounds.origin()); | 1220 gfx::Point line_end(bounds.origin()); |
| 1213 line_end.Offset(0, bounds.height()); | 1221 line_end.Offset(0, bounds.height()); |
| 1214 canvas->DrawLine(bounds.origin(), line_end, | 1222 canvas->DrawLine(bounds.origin(), line_end, |
| 1215 action_box_button_view_->GetBorderColor()); | 1223 action_box_button_view_->GetBorderColor()); |
| 1216 } | 1224 } |
| 1217 | 1225 |
| 1226 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { | |
| 1227 for (PageActionViews::const_iterator | |
| 1228 page_action_view = page_action_views_.begin(); | |
| 1229 page_action_view != page_action_views_.end(); | |
| 1230 ++page_action_view) { | |
| 1231 gfx::Rect bounds = (*page_action_view)->bounds(); | |
| 1232 int horizontal_padding = GetItemPadding() - | |
| 1233 (*page_action_view)->GetBuiltInHorizontalPadding(); | |
| 1234 // Make the bounding rectangle include the whole vertical range of the | |
| 1235 // location bar, and the mid-point pixels between adjacent page actions. | |
| 1236 // | |
| 1237 // For odd horizontal_paddings, "horizontal_padding + 1" includes the | |
| 1238 // mid-point between two page actions in the bounding rectangle. For even | |
| 1239 // paddings, the +1 is dropped, which is right since there is no pixel at | |
| 1240 // the mid-point. | |
| 1241 bounds.Inset(-(horizontal_padding + 1) / 2, 0); | |
| 1242 ToolbarModel::SecurityLevel security_level = model_->GetSecurityLevel(); | |
| 1243 extensions::PaintExtensionActionBackground( | |
| 1244 *(*page_action_view)->image_view()->page_action(), | |
| 1245 SessionID::IdForTab(GetTabContents()), | |
| 1246 canvas, bounds, | |
| 1247 GetColor(security_level, TEXT), GetColor(security_level, BACKGROUND)); | |
| 1248 } | |
| 1249 } | |
| 1250 | |
| 1218 std::string LocationBarView::GetClassName() const { | 1251 std::string LocationBarView::GetClassName() const { |
| 1219 return kViewClassName; | 1252 return kViewClassName; |
| 1220 } | 1253 } |
| 1221 | 1254 |
| 1222 bool LocationBarView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 1255 bool LocationBarView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
| 1223 #if defined(OS_WIN) | 1256 #if defined(OS_WIN) |
| 1224 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { | 1257 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { |
| 1225 if (location_entry_->model()->popup_model()->IsOpen()) { | 1258 if (location_entry_->model()->popup_model()->IsOpen()) { |
| 1226 // Return true so that the edit sees the tab and moves the selection. | 1259 // Return true so that the edit sees the tab and moves the selection. |
| 1227 return true; | 1260 return true; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1500 } | 1533 } |
| 1501 | 1534 |
| 1502 void LocationBarView::CleanupFadeAnimation() { | 1535 void LocationBarView::CleanupFadeAnimation() { |
| 1503 // Since we're no longer animating we don't need our layer. | 1536 // Since we're no longer animating we don't need our layer. |
| 1504 SetPaintToLayer(false); | 1537 SetPaintToLayer(false); |
| 1505 // Bubble labels don't need a transparent background anymore. | 1538 // Bubble labels don't need a transparent background anymore. |
| 1506 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1539 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
| 1507 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1540 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
| 1508 } | 1541 } |
| 1509 #endif // USE_AURA | 1542 #endif // USE_AURA |
| OLD | NEW |