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 FindBarButton(views::ButtonListener* listener) | |
| 106 : views::ImageButton(listener), | |
| 107 ink_drop_animation_controller_( | |
| 108 views::InkDropAnimationControllerFactory:: | |
| 109 CreateInkDropAnimationController(this)) { | |
| 110 // Sizes for ink drop animation. | |
| 111 const int kInkDropLargeSize = 24; | |
| 112 const int kInkDropLargeCornerRadius = 4; | |
| 113 const int kInkDropSmallSize = 18; | |
| 114 const int kInkDropSmallCornerRadius = 2; | |
| 115 | |
| 116 ink_drop_animation_controller_->SetInkDropSize( | |
| 117 gfx::Size(kInkDropLargeSize, kInkDropLargeSize), | |
| 118 kInkDropLargeCornerRadius, | |
| 119 gfx::Size(kInkDropSmallSize, kInkDropSmallSize), | |
| 120 kInkDropSmallCornerRadius); | |
| 121 } | |
| 122 | |
| 123 ~FindBarButton() override {} | |
| 124 | |
| 125 private: | |
| 126 void Layout() override { | |
| 127 ImageButton::Layout(); | |
| 128 | |
| 129 ink_drop_animation_controller_->SetInkDropCenter( | |
| 130 GetLocalBounds().CenterPoint()); | |
| 131 } | |
| 132 | |
| 133 void AddInkDropLayer(ui::Layer* ink_drop_layer) override { | |
| 134 SetPaintToLayer(true); | |
| 135 SetFillsBoundsOpaquely(false); | |
| 136 layer()->Add(ink_drop_layer); | |
| 137 layer()->StackAtBottom(ink_drop_layer); | |
| 138 } | |
| 139 | |
| 140 void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override { | |
| 141 layer()->Remove(ink_drop_layer); | |
| 142 SetFillsBoundsOpaquely(true); | |
| 143 SetPaintToLayer(false); | |
| 144 } | |
| 145 | |
| 146 bool OnMousePressed(const ui::MouseEvent& event) override { | |
| 147 // views::Button actions are only triggered by left and middle mouse clicks. | |
|
bruthig
2015/10/09 16:01:14
Can you double check that the middle mouse click a
Hadi
2015/10/09 17:01:18
Done.
CustomButton::OnMousePressed() and CustomBu
| |
| 148 if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) { | |
| 149 ink_drop_animation_controller_->AnimateToState( | |
| 150 views::InkDropState::ACTION_PENDING); | |
| 151 } | |
| 152 | |
| 153 return ImageButton::OnMousePressed(event); | |
| 154 } | |
| 155 | |
| 156 void OnGestureEvent(ui::GestureEvent* event) override { | |
| 157 ImageButton::OnGestureEvent(event); | |
| 158 | |
| 159 views::InkDropState ink_drop_state = views::InkDropState::HIDDEN; | |
| 160 switch (event->type()) { | |
| 161 case ui::ET_GESTURE_TAP_DOWN: | |
| 162 ink_drop_state = views::InkDropState::ACTION_PENDING; | |
| 163 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so | |
| 164 // that subsequent events for the gesture are sent to |this|. | |
| 165 event->SetHandled(); | |
| 166 break; | |
| 167 case ui::ET_GESTURE_LONG_PRESS: | |
| 168 ink_drop_state = views::InkDropState::SLOW_ACTION_PENDING; | |
| 169 break; | |
| 170 case ui::ET_GESTURE_TAP: | |
| 171 ink_drop_state = views::InkDropState::QUICK_ACTION; | |
| 172 break; | |
| 173 case ui::ET_GESTURE_LONG_TAP: | |
| 174 ink_drop_state = views::InkDropState::SLOW_ACTION; | |
| 175 break; | |
| 176 case ui::ET_GESTURE_END: | |
| 177 case ui::ET_GESTURE_TAP_CANCEL: | |
| 178 ink_drop_state = views::InkDropState::HIDDEN; | |
| 179 break; | |
| 180 default: | |
| 181 return; | |
| 182 } | |
| 183 ink_drop_animation_controller_->AnimateToState(ink_drop_state); | |
| 184 } | |
| 185 | |
| 186 void OnMouseReleased(const ui::MouseEvent& event) override { | |
| 187 ImageButton::OnMouseReleased(event); | |
| 188 ink_drop_animation_controller_->AnimateToState(views::InkDropState::HIDDEN); | |
|
bruthig
2015/10/09 16:01:14
Can you update this to check the event location si
Hadi
2015/10/09 17:01:18
Done.
| |
| 189 } | |
| 190 | |
| 191 void NotifyClick(const ui::Event& event) override { | |
| 192 ImageButton::NotifyClick(event); | |
| 193 ink_drop_animation_controller_->AnimateToState( | |
| 194 views::InkDropState::QUICK_ACTION); | |
| 195 } | |
| 196 | |
| 197 // Animation controller for the ink drop ripple effect. | |
| 198 scoped_ptr<views::InkDropAnimationController> ink_drop_animation_controller_; | |
| 199 }; | |
| 200 | |
| 100 // The match count label is like a normal label, but can process events (which | 201 // 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 | 202 // makes it easier to forward events to the text input --- see |
| 102 // FindBarView::TargetForRect). | 203 // FindBarView::TargetForRect). |
| 103 class MatchCountLabel : public views::Label { | 204 class MatchCountLabel : public views::Label { |
| 104 public: | 205 public: |
| 105 MatchCountLabel() {} | 206 MatchCountLabel() {} |
| 106 ~MatchCountLabel() override {} | 207 ~MatchCountLabel() override {} |
| 107 | 208 |
| 108 // views::Label overrides: | 209 // views::Label overrides: |
| 109 bool CanProcessEventsWithinSubtree() const override { return true; } | 210 bool CanProcessEventsWithinSubtree() const override { return true; } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 126 find_next_button_(NULL), | 227 find_next_button_(NULL), |
| 127 close_button_(NULL) { | 228 close_button_(NULL) { |
| 128 find_text_ = new views::Textfield; | 229 find_text_ = new views::Textfield; |
| 129 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); | 230 find_text_->set_id(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD); |
| 130 find_text_->set_default_width_in_chars(kDefaultCharWidth); | 231 find_text_->set_default_width_in_chars(kDefaultCharWidth); |
| 131 find_text_->set_controller(this); | 232 find_text_->set_controller(this); |
| 132 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); | 233 find_text_->SetAccessibleName(l10n_util::GetStringUTF16(IDS_ACCNAME_FIND)); |
| 133 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 234 find_text_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); |
| 134 AddChildView(find_text_); | 235 AddChildView(find_text_); |
| 135 | 236 |
| 136 find_previous_button_ = new views::ImageButton(this); | 237 find_previous_button_ = new FindBarButton(this); |
| 137 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); | 238 find_previous_button_->set_tag(FIND_PREVIOUS_TAG); |
| 138 find_previous_button_->SetFocusable(true); | 239 find_previous_button_->SetFocusable(true); |
| 139 find_previous_button_->SetTooltipText( | 240 find_previous_button_->SetTooltipText( |
| 140 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); | 241 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP)); |
| 141 find_previous_button_->SetAccessibleName( | 242 find_previous_button_->SetAccessibleName( |
| 142 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); | 243 l10n_util::GetStringUTF16(IDS_ACCNAME_PREVIOUS)); |
| 143 AddChildView(find_previous_button_); | 244 AddChildView(find_previous_button_); |
| 144 | 245 |
| 145 find_next_button_ = new views::ImageButton(this); | 246 find_next_button_ = new FindBarButton(this); |
| 146 find_next_button_->set_tag(FIND_NEXT_TAG); | 247 find_next_button_->set_tag(FIND_NEXT_TAG); |
| 147 find_next_button_->SetFocusable(true); | 248 find_next_button_->SetFocusable(true); |
| 148 find_next_button_->SetTooltipText( | 249 find_next_button_->SetTooltipText( |
| 149 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); | 250 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_NEXT_TOOLTIP)); |
| 150 find_next_button_->SetAccessibleName( | 251 find_next_button_->SetAccessibleName( |
| 151 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); | 252 l10n_util::GetStringUTF16(IDS_ACCNAME_NEXT)); |
| 152 AddChildView(find_next_button_); | 253 AddChildView(find_next_button_); |
| 153 | 254 |
| 154 close_button_ = new views::ImageButton(this); | 255 close_button_ = new FindBarButton(this); |
| 155 close_button_->set_tag(CLOSE_TAG); | 256 close_button_->set_tag(CLOSE_TAG); |
| 156 close_button_->SetFocusable(true); | 257 close_button_->SetFocusable(true); |
| 157 close_button_->SetTooltipText( | 258 close_button_->SetTooltipText( |
| 158 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); | 259 l10n_util::GetStringUTF16(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP)); |
| 159 close_button_->SetAccessibleName( | 260 close_button_->SetAccessibleName( |
| 160 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); | 261 l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE)); |
| 161 close_button_->SetAnimationDuration(0); | 262 close_button_->SetAnimationDuration(0); |
| 162 AddChildView(close_button_); | 263 AddChildView(close_button_); |
| 163 | 264 |
| 164 EnableCanvasFlippingForRTLUI(true); | 265 EnableCanvasFlippingForRTLUI(true); |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 755 void FindBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 655 if (!ui::MaterialDesignController::IsModeMaterial()) | 756 if (!ui::MaterialDesignController::IsModeMaterial()) |
| 656 return; | 757 return; |
| 657 | 758 |
| 658 SkColor color = | 759 SkColor color = |
| 659 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); | 760 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
| 660 set_background(views::Background::CreateSolidBackground(color)); | 761 set_background(views::Background::CreateSolidBackground(color)); |
| 661 match_count_text_->SetBackgroundColor(color); | 762 match_count_text_->SetBackgroundColor(color); |
| 662 match_count_text_->SetEnabledColor(kMatchTextColorMD); | 763 match_count_text_->SetEnabledColor(kMatchTextColorMD); |
| 663 } | 764 } |
| OLD | NEW |