| 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/find_bar_view.h" | 5 #include "chrome/browser/ui/views/find_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/base/theme_provider.h" | 30 #include "ui/base/theme_provider.h" |
| 31 #include "ui/events/event.h" | 31 #include "ui/events/event.h" |
| 32 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
| 33 #include "ui/gfx/color_palette.h" | 33 #include "ui/gfx/color_palette.h" |
| 34 #include "ui/gfx/paint_vector_icon.h" | 34 #include "ui/gfx/paint_vector_icon.h" |
| 35 #include "ui/gfx/vector_icons_public.h" | 35 #include "ui/gfx/vector_icons_public.h" |
| 36 #include "ui/native_theme/common_theme.h" | 36 #include "ui/native_theme/common_theme.h" |
| 37 #include "ui/native_theme/native_theme.h" | 37 #include "ui/native_theme/native_theme.h" |
| 38 #include "ui/resources/grit/ui_resources.h" | 38 #include "ui/resources/grit/ui_resources.h" |
| 39 #include "ui/views/animation/ink_drop_animation_controller.h" |
| 40 #include "ui/views/animation/ink_drop_animation_controller_factory.h" |
| 41 #include "ui/views/animation/ink_drop_host.h" |
| 39 #include "ui/views/background.h" | 42 #include "ui/views/background.h" |
| 40 #include "ui/views/border.h" | 43 #include "ui/views/border.h" |
| 41 #include "ui/views/bubble/bubble_border.h" | 44 #include "ui/views/bubble/bubble_border.h" |
| 42 #include "ui/views/controls/button/image_button.h" | 45 #include "ui/views/controls/button/image_button.h" |
| 43 #include "ui/views/controls/label.h" | 46 #include "ui/views/controls/label.h" |
| 44 #include "ui/views/controls/separator.h" | 47 #include "ui/views/controls/separator.h" |
| 45 #include "ui/views/layout/box_layout.h" | 48 #include "ui/views/layout/box_layout.h" |
| 46 #include "ui/views/painter.h" | 49 #include "ui/views/painter.h" |
| 47 #include "ui/views/view_targeter.h" | 50 #include "ui/views/view_targeter.h" |
| 48 #include "ui/views/widget/widget.h" | 51 #include "ui/views/widget/widget.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // The color of the match count label for Material Design. | 93 // The color of the match count label for Material Design. |
| 91 const SkColor kMatchTextColorMD = SkColorSetRGB(0x96, 0x96, 0x96); | 94 const SkColor kMatchTextColorMD = SkColorSetRGB(0x96, 0x96, 0x96); |
| 92 | 95 |
| 93 // Color of the vertical separator between match count and buttons. (MD only.) | 96 // Color of the vertical separator between match count and buttons. (MD only.) |
| 94 const SkColor kSeparatorColor = SkColorSetARGB(0x26, 0, 0, 0); | 97 const SkColor kSeparatorColor = SkColorSetARGB(0x26, 0, 0, 0); |
| 95 | 98 |
| 96 // The default number of average characters that the text box will be. This | 99 // The default number of average characters that the text box will be. This |
| 97 // number brings the width on a "regular fonts" system to about 300px. | 100 // number brings the width on a "regular fonts" system to about 300px. |
| 98 const int kDefaultCharWidth = 43; | 101 const int kDefaultCharWidth = 43; |
| 99 | 102 |
| 103 class FindBarButton : public views::ImageButton, public views::InkDropHost { |
| 104 public: |
| 105 explicit FindBarButton(views::ButtonListener* listener); |
| 106 ~FindBarButton() override; |
| 107 |
| 108 private: |
| 109 void Layout() override; |
| 110 void AddInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 111 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override; |
| 112 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 113 void OnGestureEvent(ui::GestureEvent* event) override; |
| 114 void OnMouseReleased(const ui::MouseEvent& event) override; |
| 115 void NotifyClick(const ui::Event& event) override; |
| 116 |
| 117 // Animation controller for the ink drop ripple effect. |
| 118 scoped_ptr<views::InkDropAnimationController> ink_drop_animation_controller_; |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(FindBarButton); |
| 121 }; |
| 122 |
| 100 // The match count label is like a normal label, but can process events (which | 123 // The match count label is like a normal label, but can process events (which |
| 101 // makes it easier to forward events to the text input --- see | 124 // makes it easier to forward events to the text input --- see |
| 102 // FindBarView::TargetForRect). | 125 // FindBarView::TargetForRect). |
| 103 class MatchCountLabel : public views::Label { | 126 class MatchCountLabel : public views::Label { |
| 104 public: | 127 public: |
| 105 MatchCountLabel() {} | 128 MatchCountLabel() {} |
| 106 ~MatchCountLabel() override {} | 129 ~MatchCountLabel() override {} |
| 107 | 130 |
| 108 // views::Label overrides: | 131 // views::Label overrides: |
| 109 bool CanProcessEventsWithinSubtree() const override { return true; } | 132 bool CanProcessEventsWithinSubtree() const override { return true; } |
| 110 | 133 |
| 111 private: | 134 private: |
| 112 DISALLOW_COPY_AND_ASSIGN(MatchCountLabel); | 135 DISALLOW_COPY_AND_ASSIGN(MatchCountLabel); |
| 113 }; | 136 }; |
| 114 | 137 |
| 115 } // namespace | 138 } // namespace |
| 116 | 139 |
| 117 //////////////////////////////////////////////////////////////////////////////// | 140 //////////////////////////////////////////////////////////////////////////////// |
| 141 // FindBarButton, public: |
| 142 |
| 143 FindBarButton::FindBarButton(views::ButtonListener* listener) |
| 144 : views::ImageButton(listener), |
| 145 ink_drop_animation_controller_( |
| 146 views::InkDropAnimationControllerFactory:: |
| 147 CreateInkDropAnimationController(this)) { |
| 148 const int kInkDropLargeSize = 32; |
| 149 const int kInkDropLargeCornerRadius = 4; |
| 150 const int kInkDropSmallSize = 24; |
| 151 const int kInkDropSmallCornerRadius = 2; |
| 152 |
| 153 ink_drop_animation_controller_->SetInkDropSize( |
| 154 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), |
| 155 kInkDropLargeCornerRadius, |
| 156 gfx::Size(kInkDropSmallSize, kInkDropSmallSize), |
| 157 kInkDropSmallCornerRadius); |
| 158 } |
| 159 |
| 160 FindBarButton::~FindBarButton() {} |
| 161 |
| 162 //////////////////////////////////////////////////////////////////////////////// |
| 163 // FindBarButton, private: |
| 164 |
| 165 void FindBarButton::Layout() { |
| 166 ImageButton::Layout(); |
| 167 |
| 168 ink_drop_animation_controller_->SetInkDropCenter( |
| 169 GetLocalBounds().CenterPoint()); |
| 170 } |
| 171 |
| 172 void FindBarButton::AddInkDropLayer(ui::Layer* ink_drop_layer) { |
| 173 SetPaintToLayer(true); |
| 174 SetFillsBoundsOpaquely(false); |
| 175 layer()->Add(ink_drop_layer); |
| 176 layer()->StackAtBottom(ink_drop_layer); |
| 177 } |
| 178 |
| 179 void FindBarButton::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { |
| 180 layer()->Remove(ink_drop_layer); |
| 181 SetFillsBoundsOpaquely(true); |
| 182 SetPaintToLayer(false); |
| 183 } |
| 184 |
| 185 bool FindBarButton::OnMousePressed(const ui::MouseEvent& event) { |
| 186 if (IsTriggerableEvent(event)) { |
| 187 ink_drop_animation_controller_->AnimateToState( |
| 188 views::InkDropState::ACTION_PENDING); |
| 189 } |
| 190 |
| 191 return ImageButton::OnMousePressed(event); |
| 192 } |
| 193 |
| 194 void FindBarButton::OnGestureEvent(ui::GestureEvent* event) { |
| 195 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN; |
| 196 switch (event->type()) { |
| 197 case ui::ET_GESTURE_TAP_DOWN: |
| 198 ink_drop_state = views::InkDropState::ACTION_PENDING; |
| 199 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so |
| 200 // that subsequent events for the gesture are sent to |this|. |
| 201 event->SetHandled(); |
| 202 break; |
| 203 case ui::ET_GESTURE_LONG_PRESS: |
| 204 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING; |
| 205 break; |
| 206 case ui::ET_GESTURE_TAP: |
| 207 ink_drop_state = views::InkDropState::QUICK_ACTION; |
| 208 break; |
| 209 case ui::ET_GESTURE_LONG_TAP: |
| 210 ink_drop_state = views::InkDropState::SLOW_ACTION; |
| 211 break; |
| 212 case ui::ET_GESTURE_END: |
| 213 case ui::ET_GESTURE_TAP_CANCEL: |
| 214 ink_drop_state = views::InkDropState::HIDDEN; |
| 215 break; |
| 216 default: |
| 217 return; |
| 218 } |
| 219 ink_drop_animation_controller_->AnimateToState(ink_drop_state); |
| 220 |
| 221 ImageButton::OnGestureEvent(event); |
| 222 } |
| 223 |
| 224 void FindBarButton::OnMouseReleased(const ui::MouseEvent& event) { |
| 225 if (!HitTestPoint(event.location())) |
| 226 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); |
| 227 |
| 228 ImageButton::OnMouseReleased(event); |
| 229 } |
| 230 |
| 231 void FindBarButton::NotifyClick(const ui::Event& event) { |
| 232 ink_drop_animation_controller_->AnimateToState( |
| 233 views::InkDropState::QUICK_ACTION); |
| 234 |
| 235 ImageButton::NotifyClick(event); |
| 236 } |
| 237 |
| 238 //////////////////////////////////////////////////////////////////////////////// |
| 118 // FindBarView, public: | 239 // FindBarView, public: |
| 119 | 240 |
| 120 FindBarView::FindBarView(FindBarHost* host) | 241 FindBarView::FindBarView(FindBarHost* host) |
| 121 : DropdownBarView(host), | 242 : DropdownBarView(host), |
| 122 find_text_(NULL), | 243 find_text_(NULL), |
| 123 match_count_text_(NULL), | 244 match_count_text_(NULL), |
| 124 focus_forwarder_view_(NULL), | 245 focus_forwarder_view_(NULL), |
| 125 find_previous_button_(NULL), | 246 find_previous_button_(NULL), |
| 126 find_next_button_(NULL), | 247 find_next_button_(NULL), |
| 127 close_button_(NULL) { | 248 close_button_(NULL) { |
| 128 find_text_ = new views::Textfield; | 249 find_text_ = new views::Textfield; |
| 129 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); | 250 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); |
| 130 find_text_->set_default_width_in_chars(kDefaultCharWidth); | 251 find_text_->set_default_width_in_chars(kDefaultCharWidth); |
| 131 find_text_->set_controller(this); | 252 find_text_->set_controller(this); |
| 132 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); | 253 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); |
| 133 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 254 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); |
| 134 AddChildView(find_text_); | 255 AddChildView(find_text_); |
| 135 | 256 |
| 136 find_previous_button_ = new views::ImageButton(this); | 257 find_previous_button_ = new FindBarButton(this); |
| 137 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); | 258 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); |
| 138 find_previous_button_->SetFocusable(true); | 259 find_previous_button_->SetFocusable(true); |
| 139 find_previous_button_->SetTooltipText( | 260 find_previous_button_->SetTooltipText( |
| 140 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); | 261 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); |
| 141 find_previous_button_->SetAccessibleName( | 262 find_previous_button_->SetAccessibleName( |
| 142 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); | 263 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); |
| 143 AddChildView(find_previous_button_); | 264 AddChildView(find_previous_button_); |
| 144 | 265 |
| 145 find_next_button_ = new views::ImageButton(this); | 266 find_next_button_ = new FindBarButton(this); |
| 146 find_next_button_->set_tag(FIND_NEXT_TAG); | 267 find_next_button_->set_tag(FIND_NEXT_TAG); |
| 147 find_next_button_->SetFocusable(true); | 268 find_next_button_->SetFocusable(true); |
| 148 find_next_button_->SetTooltipText( | 269 find_next_button_->SetTooltipText( |
| 149 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); | 270 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); |
| 150 find_next_button_->SetAccessibleName( | 271 find_next_button_->SetAccessibleName( |
| 151 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); | 272 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); |
| 152 AddChildView(find_next_button_); | 273 AddChildView(find_next_button_); |
| 153 | 274 |
| 154 close_button_ = new views::ImageButton(this); | 275 close_button_ = new FindBarButton(this); |
| 155 close_button_->set_tag(CLOSE_TAG); | 276 close_button_->set_tag(CLOSE_TAG); |
| 156 close_button_->SetFocusable(true); | 277 close_button_->SetFocusable(true); |
| 157 close_button_->SetTooltipText( | 278 close_button_->SetTooltipText( |
| 158 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); | 279 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); |
| 159 close_button_->SetAccessibleName( | 280 close_button_->SetAccessibleName( |
| 160 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 281 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 161 close_button_->SetAnimationDuration(0); | 282 close_button_->SetAnimationDuration(0); |
| 162 AddChildView(close_button_); | 283 AddChildView(close_button_); |
| 163 | 284 |
| 164 EnableCanvasFlippingForRTLUI(true); | 285 EnableCanvasFlippingForRTLUI(true); |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 775 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 655 if (!ui::MaterialDesignController::IsModeMaterial()) | 776 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 656 return; | 777 return; |
| 657 | 778 |
| 658 SkColor color = | 779 SkColor color = |
| 659 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); | 780 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
| 660 set_background(views::Background::CreateSolidBackground(color)); | 781 set_background(views::Background::CreateSolidBackground(color)); |
| 661 match_count_text_->SetBackgroundColor(color); | 782 match_count_text_->SetBackgroundColor(color); |
| 662 match_count_text_->SetEnabledColor(kMatchTextColorMD); | 783 match_count_text_->SetEnabledColor(kMatchTextColorMD); |
| 663 } | 784 } |
| OLD | NEW |