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" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 #include "ui/base/accessibility/accessible_view_state.h" | 66 #include "ui/base/accessibility/accessible_view_state.h" |
| 67 #include "ui/base/dragdrop/drag_drop_types.h" | 67 #include "ui/base/dragdrop/drag_drop_types.h" |
| 68 #include "ui/base/events/event.h" | 68 #include "ui/base/events/event.h" |
| 69 #include "ui/base/l10n/l10n_util.h" | 69 #include "ui/base/l10n/l10n_util.h" |
| 70 #include "ui/base/layout.h" | 70 #include "ui/base/layout.h" |
| 71 #include "ui/base/resource/resource_bundle.h" | 71 #include "ui/base/resource/resource_bundle.h" |
| 72 #include "ui/base/theme_provider.h" | 72 #include "ui/base/theme_provider.h" |
| 73 #include "ui/gfx/canvas.h" | 73 #include "ui/gfx/canvas.h" |
| 74 #include "ui/gfx/color_utils.h" | 74 #include "ui/gfx/color_utils.h" |
| 75 #include "ui/gfx/image/image.h" | 75 #include "ui/gfx/image/image.h" |
| 76 #include "ui/gfx/image/image_skia_operations.h" | |
| 76 #include "ui/gfx/skia_util.h" | 77 #include "ui/gfx/skia_util.h" |
| 77 #include "ui/views/border.h" | 78 #include "ui/views/border.h" |
| 78 #include "ui/views/button_drag_utils.h" | 79 #include "ui/views/button_drag_utils.h" |
| 79 #include "ui/views/controls/label.h" | 80 #include "ui/views/controls/label.h" |
| 80 #include "ui/views/widget/widget.h" | 81 #include "ui/views/widget/widget.h" |
| 81 | 82 |
| 82 #if defined(OS_WIN) && !defined(USE_AURA) | 83 #if defined(OS_WIN) && !defined(USE_AURA) |
| 83 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" | 84 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| 84 #endif | 85 #endif |
| 85 | 86 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 web_intents_button_view_(NULL), | 211 web_intents_button_view_(NULL), |
| 211 action_box_button_view_(NULL), | 212 action_box_button_view_(NULL), |
| 212 mode_(mode), | 213 mode_(mode), |
| 213 show_focus_rect_(false), | 214 show_focus_rect_(false), |
| 214 template_url_service_(NULL), | 215 template_url_service_(NULL), |
| 215 animation_offset_(0), | 216 animation_offset_(0), |
| 216 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { | 217 ALLOW_THIS_IN_INITIALIZER_LIST(view_to_focus_(this)) { |
| 217 set_id(VIEW_ID_LOCATION_BAR); | 218 set_id(VIEW_ID_LOCATION_BAR); |
| 218 | 219 |
| 219 if (mode_ == NORMAL) { | 220 if (mode_ == NORMAL) { |
| 220 painter_.reset( | 221 background_painter_.reset( |
| 221 views::Painter::CreateImagePainter( | 222 views::Painter::CreateImagePainter( |
| 222 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 223 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 223 IDR_LOCATION_BAR_BORDER).ToImageSkia(), | 224 IDR_LOCATION_BAR_BORDER).ToImageSkia(), |
| 224 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, | 225 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, |
| 225 kBorderRoundCornerHeight, kBorderRoundCornerWidth), | 226 kBorderRoundCornerHeight, kBorderRoundCornerWidth), |
| 226 true)); | 227 true)); |
| 227 } | 228 } |
| 228 | 229 |
| 229 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, | 230 edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled, |
| 230 profile_->GetPrefs(), this); | 231 profile_->GetPrefs(), this); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 const chrome::search::Mode& new_mode) { | 417 const chrome::search::Mode& new_mode) { |
| 417 #if defined(USE_AURA) | 418 #if defined(USE_AURA) |
| 418 if (new_mode.animate && old_mode.is_ntp() && new_mode.is_search()) { | 419 if (new_mode.animate && old_mode.is_ntp() && new_mode.is_search()) { |
| 419 // Fade in so the icons don't pop. | 420 // Fade in so the icons don't pop. |
| 420 StartFadeAnimation(); | 421 StartFadeAnimation(); |
| 421 } else { | 422 } else { |
| 422 // Cancel any pending animations; switch to the final state immediately. | 423 // Cancel any pending animations; switch to the final state immediately. |
| 423 StopFadeAnimation(); | 424 StopFadeAnimation(); |
| 424 } | 425 } |
| 425 #endif | 426 #endif |
| 427 | |
| 428 // Focus border may have changed, schedule paint to redraw. | |
| 429 SchedulePaint(); | |
|
sky
2012/09/20 19:50:29
Can we only do this if necessary?
kuan
2012/09/20 20:12:46
Done.
| |
| 426 } | 430 } |
| 427 | 431 |
| 428 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { | 432 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { |
| 429 RefreshContentSettingViews(); | 433 RefreshContentSettingViews(); |
| 430 ZoomBubbleView::CloseBubble(); | 434 ZoomBubbleView::CloseBubble(); |
| 431 RefreshZoomView(); | 435 RefreshZoomView(); |
| 432 RefreshPageActionViews(); | 436 RefreshPageActionViews(); |
| 433 web_intents_button_view_->Update(GetTabContents()); | 437 web_intents_button_view_->Update(GetTabContents()); |
| 434 open_pdf_in_reader_view_->Update( | 438 open_pdf_in_reader_view_->Update( |
| 435 model_->input_in_progress() ? NULL : GetTabContents()); | 439 model_->input_in_progress() ? NULL : GetTabContents()); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 int location_y = kVerticalEdgeThickness; | 663 int location_y = kVerticalEdgeThickness; |
| 660 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 664 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want |
| 661 // to position our child views in this case, because other things may be | 665 // to position our child views in this case, because other things may be |
| 662 // positioned relative to them (e.g. the "bookmark added" bubble if the user | 666 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
| 663 // hits ctrl-d). | 667 // hits ctrl-d). |
| 664 int location_height = GetInternalHeight(false); | 668 int location_height = GetInternalHeight(false); |
| 665 | 669 |
| 666 // In NTP mode, hide all location bar decorations. | 670 // In NTP mode, hide all location bar decorations. |
| 667 if (search_model_ && search_model_->mode().is_ntp()) { | 671 if (search_model_ && search_model_->mode().is_ntp()) { |
| 668 gfx::Rect location_bounds(0, location_y, width(), location_height); | 672 gfx::Rect location_bounds(0, location_y, width(), location_height); |
| 673 // The location bar border, when drawn, has colored edges that need to be | |
| 674 // inset, so that these edges won't be clipped by |location_entry_view_|. | |
| 675 // |location_y| and |location_height| already include insets of top and | |
| 676 // bottom edges, so we only need to inset for left and right edges here. | |
| 677 location_bounds.Inset(kNormalHorizontalEdgeThickness, 0); | |
| 669 location_entry_view_->SetBoundsRect(location_bounds); | 678 location_entry_view_->SetBoundsRect(location_bounds); |
| 670 for (int i = 0; i < child_count(); ++i) | 679 for (int i = 0; i < child_count(); ++i) |
| 671 if (child_at(i) != location_entry_view_) | 680 if (child_at(i) != location_entry_view_) |
| 672 child_at(i)->SetVisible(false); | 681 child_at(i)->SetVisible(false); |
| 673 return; | 682 return; |
| 674 } | 683 } |
| 675 | 684 |
| 676 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the | 685 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the |
| 677 // omnibox' parent, so there isn't any edge to account for at all. | 686 // omnibox' parent, so there isn't any edge to account for at all. |
| 678 const int kEdgeThickness = (mode_ == NORMAL) ? | 687 const int kEdgeThickness = (mode_ == NORMAL) ? |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 location_bounds.height()); | 953 location_bounds.height()); |
| 945 } | 954 } |
| 946 } | 955 } |
| 947 | 956 |
| 948 location_entry_view_->SetBoundsRect(location_bounds); | 957 location_entry_view_->SetBoundsRect(location_bounds); |
| 949 } | 958 } |
| 950 | 959 |
| 951 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 960 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 952 View::OnPaint(canvas); | 961 View::OnPaint(canvas); |
| 953 | 962 |
| 954 if (painter_.get()) { | 963 // If search mode is |NTP|, paint the background color of NTP page first; |
| 955 painter_->Paint(canvas, size()); | 964 // otherwise, there will be a white outline around the location bar border. |
| 965 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp(); | |
| 966 if (is_search_ntp) | |
| 967 canvas->DrawColor(chrome::search::kNTPBackgroundColor); | |
| 968 | |
| 969 if (background_painter_.get()) { | |
| 970 background_painter_->Paint(canvas, size()); | |
| 956 } else if (mode_ == POPUP) { | 971 } else if (mode_ == POPUP) { |
| 957 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed( | 972 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed( |
| 958 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); | 973 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); |
| 959 } | 974 } |
| 960 // When used in the app launcher, don't draw a border, the LocationBarView has | 975 // When used in the app launcher, don't draw a border, the LocationBarView has |
| 961 // its own views::Border. | 976 // its own views::Border. |
| 962 | 977 |
| 963 // Draw the background color so that the graphical elements at the edges | 978 // Draw the background color so that the graphical elements at the edges |
| 964 // appear over the correct color. (The edit draws its own background, so this | 979 // appear over the correct color. (The edit draws its own background, so this |
| 965 // isn't important for that.) | 980 // isn't important for that.) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 982 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, | 997 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, |
| 983 radius, paint); | 998 radius, paint); |
| 984 if (action_box_button_view_) | 999 if (action_box_button_view_) |
| 985 PaintActionBoxBackground(canvas, bounds); | 1000 PaintActionBoxBackground(canvas, bounds); |
| 986 } else { | 1001 } else { |
| 987 canvas->FillRect(bounds, color); | 1002 canvas->FillRect(bounds, color); |
| 988 } | 1003 } |
| 989 | 1004 |
| 990 // If |show_focus_rect_| is false but search mode is |NTP|, we still show | 1005 // If |show_focus_rect_| is false but search mode is |NTP|, we still show |
| 991 // focus rect. | 1006 // focus rect. |
| 992 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp(); | |
| 993 bool show_focus_rect = show_focus_rect_ || is_search_ntp; | 1007 bool show_focus_rect = show_focus_rect_ || is_search_ntp; |
| 994 if (show_focus_rect && HasFocus()) { | 1008 if (show_focus_rect && HasFocus()) { |
| 1009 if (is_search_ntp) { | |
|
sky
2012/09/20 19:50:29
Move this into its own function.
kuan
2012/09/20 20:12:46
Done.
| |
| 1010 // Load search focus border mask image if not already loaded. | |
| 1011 if (!search_focus_painter_.get()) { | |
| 1012 search_focus_painter_.reset( | |
| 1013 views::Painter::CreateImagePainter( | |
| 1014 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 1015 IDR_LOCATION_BAR_SEARCH_FOCUS_BORDER_MASK).ToImageSkia(), | |
| 1016 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, | |
| 1017 kBorderRoundCornerHeight, kBorderRoundCornerWidth), | |
| 1018 true)); | |
| 1019 DCHECK(search_focus_painter_.get()); | |
| 1020 } | |
| 1021 | |
| 1022 // On first canvas, draw rounded rect with system highlight color. | |
| 1023 gfx::Canvas border_canvas(size(), canvas->scale_factor(), false); | |
| 1024 SkPaint paint; | |
| 1025 paint.setColor(ui::NativeTheme::instance()->GetSystemColor( | |
| 1026 ui::NativeTheme::kColorId_FocusedBorderColor)); | |
| 1027 paint.setStyle(SkPaint::kFill_Style); | |
| 1028 paint.setAntiAlias(true); | |
| 1029 border_canvas.DrawRoundRect(GetLocalBounds(), kBorderCornerRadius, paint); | |
| 1030 | |
| 1031 // On second canvas, draw the mask image. | |
| 1032 gfx::Canvas mask_canvas(size(), canvas->scale_factor(), false); | |
| 1033 search_focus_painter_->Paint(&mask_canvas, size()); | |
| 1034 | |
| 1035 // Create a masked image from the 2 canvases, and draw the final image | |
| 1036 // on the destination canvas. | |
| 1037 gfx::ImageSkia focus_image = | |
| 1038 gfx::ImageSkiaOperations::CreateMaskedImage( | |
| 1039 gfx::ImageSkia(border_canvas.ExtractImageRep()), | |
| 1040 gfx::ImageSkia(mask_canvas.ExtractImageRep())); | |
| 1041 canvas->DrawImageInt(focus_image, 0, 0); | |
| 1042 return; | |
| 1043 } | |
| 1044 | |
| 995 gfx::Rect r = location_entry_view_->bounds(); | 1045 gfx::Rect r = location_entry_view_->bounds(); |
| 996 | |
| 997 // TODO(jamescook): Is this still needed? | 1046 // TODO(jamescook): Is this still needed? |
| 998 #if defined(OS_WIN) | 1047 #if defined(OS_WIN) |
| 999 r.Inset(-1, -1); | 1048 r.Inset(-1, -1); |
| 1000 #else | 1049 #else |
| 1001 r.Inset(-1, 0); | 1050 r.Inset(-1, 0); |
| 1002 #endif | 1051 #endif |
| 1003 canvas->DrawFocusRect(r); | 1052 canvas->DrawFocusRect(r); |
| 1004 } | 1053 } |
| 1005 } | 1054 } |
| 1006 | 1055 |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1580 } | 1629 } |
| 1581 | 1630 |
| 1582 void LocationBarView::CleanupFadeAnimation() { | 1631 void LocationBarView::CleanupFadeAnimation() { |
| 1583 // Since we're no longer animating we don't need our layer. | 1632 // Since we're no longer animating we don't need our layer. |
| 1584 SetPaintToLayer(false); | 1633 SetPaintToLayer(false); |
| 1585 // Bubble labels don't need a transparent background anymore. | 1634 // Bubble labels don't need a transparent background anymore. |
| 1586 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1635 ev_bubble_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
| 1587 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); | 1636 selected_keyword_view_->SetLabelBackgroundColor(SK_ColorWHITE); |
| 1588 } | 1637 } |
| 1589 #endif // USE_AURA | 1638 #endif // USE_AURA |
| OLD | NEW |