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/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); | |
|
Peter Kasting
2015/10/13 19:09:23
You addressed my previous "ordering inconsistency"
Hadi
2015/10/13 19:17:32
Sorry for not addressing the previous feedback pro
| |
| 222 } | |
| 223 | |
| 224 void FindBarButton::OnMouseReleased(const ui::MouseEvent& event) { | |
| 225 ImageButton::OnMouseReleased(event); | |
| 226 | |
| 227 if (!HitTestPoint(event.location())) | |
| 228 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | |
| 229 } | |
| 230 | |
| 231 void FindBarButton::NotifyClick(const ui::Event& event) { | |
| 232 ImageButton::NotifyClick(event); | |
| 233 ink_drop_animation_controller_->AnimateToState( | |
| 234 views::InkDropState::QUICK_ACTION); | |
| 235 } | |
| 236 | |
| 237 //////////////////////////////////////////////////////////////////////////////// | |
| 118 // FindBarView, public: | 238 // FindBarView, public: |
| 119 | 239 |
| 120 FindBarView::FindBarView(FindBarHost* host) | 240 FindBarView::FindBarView(FindBarHost* host) |
| 121 : DropdownBarView(host), | 241 : DropdownBarView(host), |
| 122 find_text_(NULL), | 242 find_text_(NULL), |
| 123 match_count_text_(NULL), | 243 match_count_text_(NULL), |
| 124 focus_forwarder_view_(NULL), | 244 focus_forwarder_view_(NULL), |
| 125 find_previous_button_(NULL), | 245 find_previous_button_(NULL), |
| 126 find_next_button_(NULL), | 246 find_next_button_(NULL), |
| 127 close_button_(NULL) { | 247 close_button_(NULL) { |
| 128 find_text_ = new views::Textfield; | 248 find_text_ = new views::Textfield; |
| 129 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); | 249 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); |
| 130 find_text_->set_default_width_in_chars(kDefaultCharWidth); | 250 find_text_->set_default_width_in_chars(kDefaultCharWidth); |
| 131 find_text_->set_controller(this); | 251 find_text_->set_controller(this); |
| 132 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); | 252 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); |
| 133 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 253 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); |
| 134 AddChildView(find_text_); | 254 AddChildView(find_text_); |
| 135 | 255 |
| 136 find_previous_button_ = new views::ImageButton(this); | 256 find_previous_button_ = new FindBarButton(this); |
| 137 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); | 257 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); |
| 138 find_previous_button_->SetFocusable(true); | 258 find_previous_button_->SetFocusable(true); |
| 139 find_previous_button_->SetTooltipText( | 259 find_previous_button_->SetTooltipText( |
| 140 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); | 260 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); |
| 141 find_previous_button_->SetAccessibleName( | 261 find_previous_button_->SetAccessibleName( |
| 142 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); | 262 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); |
| 143 AddChildView(find_previous_button_); | 263 AddChildView(find_previous_button_); |
| 144 | 264 |
| 145 find_next_button_ = new views::ImageButton(this); | 265 find_next_button_ = new FindBarButton(this); |
| 146 find_next_button_->set_tag(FIND_NEXT_TAG); | 266 find_next_button_->set_tag(FIND_NEXT_TAG); |
| 147 find_next_button_->SetFocusable(true); | 267 find_next_button_->SetFocusable(true); |
| 148 find_next_button_->SetTooltipText( | 268 find_next_button_->SetTooltipText( |
| 149 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); | 269 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); |
| 150 find_next_button_->SetAccessibleName( | 270 find_next_button_->SetAccessibleName( |
| 151 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); | 271 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); |
| 152 AddChildView(find_next_button_); | 272 AddChildView(find_next_button_); |
| 153 | 273 |
| 154 close_button_ = new views::ImageButton(this); | 274 close_button_ = new FindBarButton(this); |
| 155 close_button_->set_tag(CLOSE_TAG); | 275 close_button_->set_tag(CLOSE_TAG); |
| 156 close_button_->SetFocusable(true); | 276 close_button_->SetFocusable(true); |
| 157 close_button_->SetTooltipText( | 277 close_button_->SetTooltipText( |
| 158 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); | 278 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); |
| 159 close_button_->SetAccessibleName( | 279 close_button_->SetAccessibleName( |
| 160 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 280 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 161 close_button_->SetAnimationDuration(0); | 281 close_button_->SetAnimationDuration(0); |
| 162 AddChildView(close_button_); | 282 AddChildView(close_button_); |
| 163 | 283 |
| 164 EnableCanvasFlippingForRTLUI(true); | 284 EnableCanvasFlippingForRTLUI(true); |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 774 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 655 if (!ui::MaterialDesignController::IsModeMaterial()) | 775 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 656 return; | 776 return; |
| 657 | 777 |
| 658 SkColor color = | 778 SkColor color = |
| 659 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); | 779 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
| 660 set_background(views::Background::CreateSolidBackground(color)); | 780 set_background(views::Background::CreateSolidBackground(color)); |
| 661 match_count_text_->SetBackgroundColor(color); | 781 match_count_text_->SetBackgroundColor(color); |
| 662 match_count_text_->SetEnabledColor(kMatchTextColorMD); | 782 match_count_text_->SetEnabledColor(kMatchTextColorMD); |
| 663 } | 783 } |
| OLD | NEW |