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 330 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 // If mode transitions from |NTP|, repaint to not draw focus border. | |
|
dhollowa
2012/09/20 18:33:13
This would be simpler if you just always schedule
kuan
2012/09/20 18:55:50
Done.
| |
| 429 // If mode transitions to |NTP|, repaint to draw focus border. | |
| 430 if (old_mode.is_ntp() || new_mode.is_ntp()) { | |
| 431 if (new_mode.is_ntp() && !search_focus_painter_.get()) { | |
| 432 search_focus_painter_.reset( | |
| 433 views::Painter::CreateImagePainter( | |
| 434 *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
| 435 IDR_LOCATION_BAR_SEARCH_FOCUS_BORDER_MASK).ToImageSkia(), | |
| 436 gfx::Insets(kBorderRoundCornerHeight, kBorderRoundCornerWidth, | |
| 437 kBorderRoundCornerHeight, kBorderRoundCornerWidth), | |
| 438 true)); | |
| 439 } | |
| 440 SchedulePaint(); | |
| 441 } | |
| 426 } | 442 } |
| 427 | 443 |
| 428 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { | 444 void LocationBarView::Update(const WebContents* tab_for_state_restoring) { |
| 429 RefreshContentSettingViews(); | 445 RefreshContentSettingViews(); |
| 430 ZoomBubbleView::CloseBubble(); | 446 ZoomBubbleView::CloseBubble(); |
| 431 RefreshZoomView(); | 447 RefreshZoomView(); |
| 432 RefreshPageActionViews(); | 448 RefreshPageActionViews(); |
| 433 web_intents_button_view_->Update(GetTabContents()); | 449 web_intents_button_view_->Update(GetTabContents()); |
| 434 open_pdf_in_reader_view_->Update( | 450 open_pdf_in_reader_view_->Update( |
| 435 model_->input_in_progress() ? NULL : GetTabContents()); | 451 model_->input_in_progress() ? NULL : GetTabContents()); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 659 int location_y = kVerticalEdgeThickness; | 675 int location_y = kVerticalEdgeThickness; |
| 660 // In some cases (e.g. fullscreen mode) we may have 0 height. We still want | 676 // 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 | 677 // 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 | 678 // positioned relative to them (e.g. the "bookmark added" bubble if the user |
| 663 // hits ctrl-d). | 679 // hits ctrl-d). |
| 664 int location_height = GetInternalHeight(false); | 680 int location_height = GetInternalHeight(false); |
| 665 | 681 |
| 666 // In NTP mode, hide all location bar decorations. | 682 // In NTP mode, hide all location bar decorations. |
| 667 if (search_model_ && search_model_->mode().is_ntp()) { | 683 if (search_model_ && search_model_->mode().is_ntp()) { |
| 668 gfx::Rect location_bounds(0, location_y, width(), location_height); | 684 gfx::Rect location_bounds(0, location_y, width(), location_height); |
| 685 // The location bar border, when drawn, has colored edges that need to be | |
| 686 // inset, so that these edges won't be clipped by |location_entry_view_|. | |
| 687 // |location_y| and |location_height| already include insets of top and | |
| 688 // bottom edges, so we only need to inset for left and right edges here. | |
| 689 location_bounds.Inset(kNormalHorizontalEdgeThickness, 0); | |
| 669 location_entry_view_->SetBoundsRect(location_bounds); | 690 location_entry_view_->SetBoundsRect(location_bounds); |
| 670 for (int i = 0; i < child_count(); ++i) | 691 for (int i = 0; i < child_count(); ++i) |
| 671 if (child_at(i) != location_entry_view_) | 692 if (child_at(i) != location_entry_view_) |
| 672 child_at(i)->SetVisible(false); | 693 child_at(i)->SetVisible(false); |
| 673 return; | 694 return; |
| 674 } | 695 } |
| 675 | 696 |
| 676 // The edge stroke is 1 px thick. In popup mode, the edges are drawn by the | 697 // 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. | 698 // omnibox' parent, so there isn't any edge to account for at all. |
| 678 const int kEdgeThickness = (mode_ == NORMAL) ? | 699 const int kEdgeThickness = (mode_ == NORMAL) ? |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 944 location_bounds.height()); | 965 location_bounds.height()); |
| 945 } | 966 } |
| 946 } | 967 } |
| 947 | 968 |
| 948 location_entry_view_->SetBoundsRect(location_bounds); | 969 location_entry_view_->SetBoundsRect(location_bounds); |
| 949 } | 970 } |
| 950 | 971 |
| 951 void LocationBarView::OnPaint(gfx::Canvas* canvas) { | 972 void LocationBarView::OnPaint(gfx::Canvas* canvas) { |
| 952 View::OnPaint(canvas); | 973 View::OnPaint(canvas); |
| 953 | 974 |
| 975 // If search mode is |NTP|, paint the background color of NTP page first; | |
| 976 // otherwise, there will be a white outline around the location bar border. | |
| 977 bool is_search_ntp = search_model_ && search_model_->mode().is_ntp(); | |
| 978 if (is_search_ntp) | |
| 979 canvas->DrawColor(chrome::search::kNTPBackgroundColor); | |
| 980 | |
| 954 if (painter_.get()) { | 981 if (painter_.get()) { |
| 955 painter_->Paint(canvas, size()); | 982 painter_->Paint(canvas, size()); |
| 956 } else if (mode_ == POPUP) { | 983 } else if (mode_ == POPUP) { |
| 957 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed( | 984 canvas->TileImageInt(*GetThemeProvider()->GetImageSkiaNamed( |
| 958 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); | 985 IDR_LOCATIONBG_POPUPMODE_CENTER), 0, 0, 0, 0, width(), height()); |
| 959 } | 986 } |
| 960 // When used in the app launcher, don't draw a border, the LocationBarView has | 987 // When used in the app launcher, don't draw a border, the LocationBarView has |
| 961 // its own views::Border. | 988 // its own views::Border. |
| 962 | 989 |
| 963 // Draw the background color so that the graphical elements at the edges | 990 // Draw the background color so that the graphical elements at the edges |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 982 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, | 1009 canvas->sk_canvas()->drawRoundRect(gfx::RectToSkRect(bounds), radius, |
| 983 radius, paint); | 1010 radius, paint); |
| 984 if (action_box_button_view_) | 1011 if (action_box_button_view_) |
| 985 PaintActionBoxBackground(canvas, bounds); | 1012 PaintActionBoxBackground(canvas, bounds); |
| 986 } else { | 1013 } else { |
| 987 canvas->FillRect(bounds, color); | 1014 canvas->FillRect(bounds, color); |
| 988 } | 1015 } |
| 989 | 1016 |
| 990 // If |show_focus_rect_| is false but search mode is |NTP|, we still show | 1017 // If |show_focus_rect_| is false but search mode is |NTP|, we still show |
| 991 // focus rect. | 1018 // 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; | 1019 bool show_focus_rect = show_focus_rect_ || is_search_ntp; |
| 994 if (show_focus_rect && HasFocus()) { | 1020 if (show_focus_rect && HasFocus()) { |
| 1021 if (is_search_ntp && search_focus_painter_.get()) { | |
| 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 focuse_image = | |
| 1038 gfx::ImageSkiaOperations::CreateMaskedImage( | |
| 1039 gfx::ImageSkia(border_canvas.ExtractImageRep()), | |
| 1040 gfx::ImageSkia(mask_canvas.ExtractImageRep())); | |
| 1041 canvas->DrawImageInt(focuse_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 |