| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/search_engines/template_url.h" | 26 #include "chrome/browser/search_engines/template_url.h" |
| 27 #include "chrome/browser/search_engines/template_url_service.h" | 27 #include "chrome/browser/search_engines/template_url_service.h" |
| 28 #include "chrome/browser/search_engines/template_url_service_factory.h" | 28 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 29 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
| 30 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
| 31 #include "chrome/browser/ui/browser_tabstrip.h" | 31 #include "chrome/browser/ui/browser_tabstrip.h" |
| 32 #include "chrome/browser/ui/omnibox/location_bar_util.h" |
| 32 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 33 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
| 33 #include "chrome/browser/ui/search/search.h" | 34 #include "chrome/browser/ui/search/search.h" |
| 34 #include "chrome/browser/ui/search/search_model.h" | 35 #include "chrome/browser/ui/search/search_model.h" |
| 35 #include "chrome/browser/ui/search/search_types.h" | 36 #include "chrome/browser/ui/search/search_types.h" |
| 36 #include "chrome/browser/ui/search/search_ui.h" | 37 #include "chrome/browser/ui/search/search_ui.h" |
| 37 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 38 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 38 #include "chrome/browser/ui/view_ids.h" | 39 #include "chrome/browser/ui/view_ids.h" |
| 39 #include "chrome/browser/ui/views/browser_dialogs.h" | 40 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 40 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 41 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 41 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" | 42 #include "chrome/browser/ui/views/location_bar/action_box_button_view.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 111 |
| 111 // Height of the location bar's round corner region. | 112 // Height of the location bar's round corner region. |
| 112 const int kBorderRoundCornerHeight = 5; | 113 const int kBorderRoundCornerHeight = 5; |
| 113 // Width of location bar's round corner region. | 114 // Width of location bar's round corner region. |
| 114 const int kBorderRoundCornerWidth = 4; | 115 const int kBorderRoundCornerWidth = 4; |
| 115 // Radius of the round corners inside the location bar. | 116 // Radius of the round corners inside the location bar. |
| 116 const int kBorderCornerRadius = 2; | 117 const int kBorderCornerRadius = 2; |
| 117 | 118 |
| 118 const int kDesktopItemPadding = 3; | 119 const int kDesktopItemPadding = 3; |
| 119 const int kDesktopEdgeItemPadding = kDesktopItemPadding; | 120 const int kDesktopEdgeItemPadding = kDesktopItemPadding; |
| 121 const int kDesktopScriptBadgeItemPadding = 9; |
| 122 const int kDesktopScriptBadgeEdgeItemPadding = kDesktopScriptBadgeItemPadding; |
| 120 | 123 |
| 121 const int kTouchItemPadding = 8; | 124 const int kTouchItemPadding = 8; |
| 122 const int kTouchEdgeItemPadding = kTouchItemPadding; | 125 const int kTouchEdgeItemPadding = kTouchItemPadding; |
| 123 | 126 |
| 124 // Extra padding for the height of the omnibox in search mode. | 127 // Extra padding for the height of the omnibox in search mode. |
| 125 const int kSearchEditHeightPadding = 2; | 128 const int kSearchEditHeightPadding = 2; |
| 126 | 129 |
| 127 } // namespace | 130 } // namespace |
| 128 | 131 |
| 129 // static | 132 // static |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 389 } |
| 387 | 390 |
| 388 default: | 391 default: |
| 389 NOTREACHED(); | 392 NOTREACHED(); |
| 390 return GetColor(security_level, TEXT); | 393 return GetColor(security_level, TEXT); |
| 391 } | 394 } |
| 392 } | 395 } |
| 393 | 396 |
| 394 // static | 397 // static |
| 395 int LocationBarView::GetItemPadding() { | 398 int LocationBarView::GetItemPadding() { |
| 396 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? | 399 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) |
| 397 kTouchItemPadding : kDesktopItemPadding; | 400 return kTouchItemPadding; |
| 401 return extensions::switch_utils::AreScriptBadgesEnabled() ? |
| 402 kDesktopScriptBadgeItemPadding : kDesktopItemPadding; |
| 398 } | 403 } |
| 399 | 404 |
| 400 // static | 405 // static |
| 401 int LocationBarView::GetEdgeItemPadding() { | 406 int LocationBarView::GetEdgeItemPadding() { |
| 402 return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? | 407 if (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) |
| 403 kTouchEdgeItemPadding : kDesktopEdgeItemPadding; | 408 return kTouchEdgeItemPadding; |
| 409 return extensions::switch_utils::AreScriptBadgesEnabled() ? |
| 410 kDesktopScriptBadgeEdgeItemPadding : kDesktopEdgeItemPadding; |
| 404 } | 411 } |
| 405 | 412 |
| 406 // DropdownBarHostDelegate | 413 // DropdownBarHostDelegate |
| 407 void LocationBarView::SetFocusAndSelection(bool select_all) { | 414 void LocationBarView::SetFocusAndSelection(bool select_all) { |
| 408 FocusLocation(select_all); | 415 FocusLocation(select_all); |
| 409 } | 416 } |
| 410 | 417 |
| 411 void LocationBarView::SetAnimationOffset(int offset) { | 418 void LocationBarView::SetAnimationOffset(int offset) { |
| 412 animation_offset_ = offset; | 419 animation_offset_ = offset; |
| 413 } | 420 } |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 paint.setStyle(SkPaint::kFill_Style); | 983 paint.setStyle(SkPaint::kFill_Style); |
| 977 paint.setAntiAlias(true); | 984 paint.setAntiAlias(true); |
| 978 // TODO(jamescook): Make the corners of the dropdown match the corners of | 985 // TODO(jamescook): Make the corners of the dropdown match the corners of |
| 979 // the omnibox. | 986 // the omnibox. |
| 980 const SkScalar radius(SkIntToScalar(kBorderCornerRadius)); | 987 const SkScalar radius(SkIntToScalar(kBorderCornerRadius)); |
| 981 bounds.Inset(kNormalHorizontalEdgeThickness, 0); | 988 bounds.Inset(kNormalHorizontalEdgeThickness, 0); |
| 982 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, | 989 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, |
| 983 radius, paint); | 990 radius, paint); |
| 984 if (action_box_button_view_) | 991 if (action_box_button_view_) |
| 985 PaintActionBoxBackground(canvas, bounds); | 992 PaintActionBoxBackground(canvas, bounds); |
| 993 PaintPageActionBackgrounds(canvas); |
| 986 } else { | 994 } else { |
| 987 canvas->FillRect(bounds, color); | 995 canvas->FillRect(bounds, color); |
| 988 } | 996 } |
| 989 | 997 |
| 990 // If |show_focus_rect_| is false but search mode is |NTP|, we still show | 998 // If |show_focus_rect_| is false but search mode is |NTP|, we still show |
| 991 // focus rect. | 999 // focus rect. |
| 992 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp(); | 1000 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp(); |
| 993 bool show_focus_rect = show_focus_rect_ || is_search_ntp; | 1001 bool show_focus_rect = show_focus_rect_ || is_search_ntp; |
| 994 if (show_focus_rect && HasFocus()) { | 1002 if (show_focus_rect && HasFocus()) { |
| 995 gfx::Rect r = location_entry_view_->bounds(); | 1003 gfx::Rect r = location_entry_view_->bounds(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 bounds.set_width(kBorderCornerRadius); | 1307 bounds.set_width(kBorderCornerRadius); |
| 1300 canvas->DrawRect(bounds, paint); | 1308 canvas->DrawRect(bounds, paint); |
| 1301 | 1309 |
| 1302 // Draw left border. | 1310 // Draw left border. |
| 1303 gfx::Point line_end(bounds.origin()); | 1311 gfx::Point line_end(bounds.origin()); |
| 1304 line_end.Offset(0, bounds.height()); | 1312 line_end.Offset(0, bounds.height()); |
| 1305 canvas->DrawLine(bounds.origin(), line_end, | 1313 canvas->DrawLine(bounds.origin(), line_end, |
| 1306 action_box_button_view_->GetBorderColor()); | 1314 action_box_button_view_->GetBorderColor()); |
| 1307 } | 1315 } |
| 1308 | 1316 |
| 1317 void LocationBarView::PaintPageActionBackgrounds(gfx::Canvas* canvas) { |
| 1318 for (PageActionViews::const_iterator |
| 1319 page_action_view = page_action_views_.begin(); |
| 1320 page_action_view != page_action_views_.end(); |
| 1321 ++page_action_view) { |
| 1322 gfx::Rect bounds = (*page_action_view)->bounds(); |
| 1323 int horizontal_padding = GetItemPadding() - |
| 1324 (*page_action_view)->GetBuiltInHorizontalPadding(); |
| 1325 // Make the bounding rectangle include the whole vertical range of the |
| 1326 // location bar, and the mid-point pixels between adjacent page actions. |
| 1327 // |
| 1328 // For odd horizontal_paddings, "horizontal_padding + 1" includes the |
| 1329 // mid-point between two page actions in the bounding rectangle. For even |
| 1330 // paddings, the +1 is dropped, which is right since there is no pixel at |
| 1331 // the mid-point. |
| 1332 bounds.Inset(-(horizontal_padding + 1) / 2, 0); |
| 1333 ToolbarModel::SecurityLevel security_level = model_->GetSecurityLevel(); |
| 1334 location_bar_util::PaintExtensionActionBackground( |
| 1335 *(*page_action_view)->image_view()->page_action(), |
| 1336 SessionID::IdForTab(GetTabContents()->web_contents()), |
| 1337 canvas, bounds, |
| 1338 GetColor(security_level, TEXT), GetColor(security_level, BACKGROUND)); |
| 1339 } |
| 1340 } |
| 1341 |
| 1309 std::string LocationBarView::GetClassName() const { | 1342 std::string LocationBarView::GetClassName() const { |
| 1310 return kViewClassName; | 1343 return kViewClassName; |
| 1311 } | 1344 } |
| 1312 | 1345 |
| 1313 bool LocationBarView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { | 1346 bool LocationBarView::SkipDefaultKeyEventProcessing(const ui::KeyEvent& event) { |
| 1314 #if defined(OS_WIN) | 1347 #if defined(OS_WIN) |
| 1315 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { | 1348 if (views::FocusManager::IsTabTraversalKeyEvent(event)) { |
| 1316 if (location_entry_->model()->popup_model()->IsOpen()) { | 1349 if (location_entry_->model()->popup_model()->IsOpen()) { |
| 1317 // Return true so that the edit sees the tab and moves the selection. | 1350 // Return true so that the edit sees the tab and moves the selection. |
| 1318 return true; | 1351 return true; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 } | 1624 } |
| 1592 | 1625 |
| 1593 void LocationBarView::CleanupFadeAnimation() { | 1626 void LocationBarView::CleanupFadeAnimation() { |
| 1594 // Since we're no longer animating we don't need our layer. | 1627 // Since we're no longer animating we don't need our layer. |
| 1595 SetPaintToLayer(false); | 1628 SetPaintToLayer(false); |
| 1596 // Bubble labels don't need a transparent background anymore. | 1629 // Bubble labels don't need a transparent background anymore. |
| 1597 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1630 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
| 1598 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1631 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
| 1599 } | 1632 } |
| 1600 #endif // USE_AURA | 1633 #endif // USE_AURA |
| OLD | NEW |