Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ui/views/controls/textfield/textfield.cc

Issue 2395033002: Harmony - Don't paint focus ring on unless border requests it. (Closed)
Patch Set: uninstall Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/views/controls/textfield/textfield.h" 5 #include "ui/views/controls/textfield/textfield.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/trace_event/trace_event.h" 10 #include "base/trace_event/trace_event.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 placeholder_text_color_(kDefaultPlaceholderTextColor), 254 placeholder_text_color_(kDefaultPlaceholderTextColor),
255 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT), 255 text_input_type_(ui::TEXT_INPUT_TYPE_TEXT),
256 text_input_flags_(0), 256 text_input_flags_(0),
257 performing_user_action_(false), 257 performing_user_action_(false),
258 skip_input_method_cancel_composition_(false), 258 skip_input_method_cancel_composition_(false),
259 drop_cursor_visible_(false), 259 drop_cursor_visible_(false),
260 initiating_drag_(false), 260 initiating_drag_(false),
261 aggregated_clicks_(0), 261 aggregated_clicks_(0),
262 drag_start_display_offset_(0), 262 drag_start_display_offset_(0),
263 touch_handles_hidden_due_to_scroll_(false), 263 touch_handles_hidden_due_to_scroll_(false),
264 use_focus_ring_(ui::MaterialDesignController::IsSecondaryUiMaterial()),
264 weak_ptr_factory_(this) { 265 weak_ptr_factory_(this) {
265 set_context_menu_controller(this); 266 set_context_menu_controller(this);
266 set_drag_controller(this); 267 set_drag_controller(this);
267 GetRenderText()->SetFontList(GetDefaultFontList()); 268 GetRenderText()->SetFontList(GetDefaultFontList());
268 SetBorder(std::unique_ptr<Border>(new FocusableBorder())); 269 View::SetBorder(std::unique_ptr<Border>(new FocusableBorder()));
269 SetFocusBehavior(FocusBehavior::ALWAYS); 270 SetFocusBehavior(FocusBehavior::ALWAYS);
270 271
271 // These allow BrowserView to pass edit commands from the Chrome menu to us 272 // These allow BrowserView to pass edit commands from the Chrome menu to us
272 // when we're focused by simply asking the FocusManager to 273 // when we're focused by simply asking the FocusManager to
273 // ProcessAccelerator() with the relevant accelerators. 274 // ProcessAccelerator() with the relevant accelerators.
274 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); 275 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN));
275 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); 276 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN));
276 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); 277 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN));
277 } 278 }
278 279
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 gfx::Size Textfield::GetPreferredSize() const { 552 gfx::Size Textfield::GetPreferredSize() const {
552 const gfx::Insets& insets = GetInsets(); 553 const gfx::Insets& insets = GetInsets();
553 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) + 554 return gfx::Size(GetFontList().GetExpectedTextWidth(default_width_in_chars_) +
554 insets.width(), GetFontList().GetHeight() + insets.height()); 555 insets.width(), GetFontList().GetHeight() + insets.height());
555 } 556 }
556 557
557 const char* Textfield::GetClassName() const { 558 const char* Textfield::GetClassName() const {
558 return kViewClassName; 559 return kViewClassName;
559 } 560 }
560 561
562 void Textfield::SetBorder(std::unique_ptr<Border> b) {
563 if (use_focus_ring_ && HasFocus())
564 FocusRing::Uninstall(this);
565 use_focus_ring_ = false;
566 View::SetBorder(std::move(b));
567 }
568
561 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) { 569 gfx::NativeCursor Textfield::GetCursor(const ui::MouseEvent& event) {
562 bool in_selection = GetRenderText()->IsPointInSelection(event.location()); 570 bool in_selection = GetRenderText()->IsPointInSelection(event.location());
563 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED; 571 bool drag_event = event.type() == ui::ET_MOUSE_DRAGGED;
564 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection); 572 bool text_cursor = !initiating_drag_ && (drag_event || !in_selection);
565 return text_cursor ? GetNativeIBeamCursor() : gfx::kNullCursor; 573 return text_cursor ? GetNativeIBeamCursor() : gfx::kNullCursor;
566 } 574 }
567 575
568 bool Textfield::OnMousePressed(const ui::MouseEvent& event) { 576 bool Textfield::OnMousePressed(const ui::MouseEvent& event) {
569 TrackMouseClicks(event); 577 TrackMouseClicks(event);
570 578
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 void Textfield::OnPaint(gfx::Canvas* canvas) { 988 void Textfield::OnPaint(gfx::Canvas* canvas) {
981 OnPaintBackground(canvas); 989 OnPaintBackground(canvas);
982 PaintTextAndCursor(canvas); 990 PaintTextAndCursor(canvas);
983 OnPaintBorder(canvas); 991 OnPaintBorder(canvas);
984 } 992 }
985 993
986 void Textfield::OnFocus() { 994 void Textfield::OnFocus() {
987 GetRenderText()->set_focused(true); 995 GetRenderText()->set_focused(true);
988 if (ShouldShowCursor()) 996 if (ShouldShowCursor())
989 GetRenderText()->set_cursor_visible(true); 997 GetRenderText()->set_cursor_visible(true);
990 SchedulePaint();
991 if (GetInputMethod()) 998 if (GetInputMethod())
992 GetInputMethod()->SetFocusedTextInputClient(this); 999 GetInputMethod()->SetFocusedTextInputClient(this);
993 OnCaretBoundsChanged(); 1000 OnCaretBoundsChanged();
994 if (ShouldBlinkCursor()) 1001 if (ShouldBlinkCursor())
995 StartBlinkingCursor(); 1002 StartBlinkingCursor();
1003 if (use_focus_ring_)
1004 FocusRing::Install(this);
1005 SchedulePaint();
996 View::OnFocus(); 1006 View::OnFocus();
997 SchedulePaint();
998 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
999 FocusRing::Install(this);
1000 } 1007 }
1001 1008
1002 void Textfield::OnBlur() { 1009 void Textfield::OnBlur() {
1003 gfx::RenderText* render_text = GetRenderText(); 1010 gfx::RenderText* render_text = GetRenderText();
1004 render_text->set_focused(false); 1011 render_text->set_focused(false);
1005 if (GetInputMethod()) 1012 if (GetInputMethod())
1006 GetInputMethod()->DetachTextInputClient(this); 1013 GetInputMethod()->DetachTextInputClient(this);
1007 StopBlinkingCursor(); 1014 StopBlinkingCursor();
1008 if (render_text->cursor_visible()) { 1015 if (render_text->cursor_visible()) {
1009 render_text->set_cursor_visible(false); 1016 render_text->set_cursor_visible(false);
1010 RepaintCursor(); 1017 RepaintCursor();
1011 } 1018 }
1012 1019
1013 DestroyTouchSelection(); 1020 DestroyTouchSelection();
1014 1021
1015 // Border typically draws focus indicator. 1022 if (use_focus_ring_)
1023 FocusRing::Uninstall(this);
1016 SchedulePaint(); 1024 SchedulePaint();
1017 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) 1025 View::OnBlur();
1018 FocusRing::Uninstall(this);
1019 } 1026 }
1020 1027
1021 gfx::Point Textfield::GetKeyboardContextMenuLocation() { 1028 gfx::Point Textfield::GetKeyboardContextMenuLocation() {
1022 return GetCaretBounds().bottom_right(); 1029 return GetCaretBounds().bottom_right();
1023 } 1030 }
1024 1031
1025 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) { 1032 void Textfield::OnNativeThemeChanged(const ui::NativeTheme* theme) {
1026 gfx::RenderText* render_text = GetRenderText(); 1033 gfx::RenderText* render_text = GetRenderText();
1027 render_text->SetColor(GetTextColor()); 1034 render_text->SetColor(GetTextColor());
1028 UpdateBackgroundColor(); 1035 UpdateBackgroundColor();
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 } 2085 }
2079 2086
2080 void Textfield::OnCursorBlinkTimerFired() { 2087 void Textfield::OnCursorBlinkTimerFired() {
2081 DCHECK(ShouldBlinkCursor()); 2088 DCHECK(ShouldBlinkCursor());
2082 gfx::RenderText* render_text = GetRenderText(); 2089 gfx::RenderText* render_text = GetRenderText();
2083 render_text->set_cursor_visible(!render_text->cursor_visible()); 2090 render_text->set_cursor_visible(!render_text->cursor_visible());
2084 RepaintCursor(); 2091 RepaintCursor();
2085 } 2092 }
2086 2093
2087 } // namespace views 2094 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698