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

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

Issue 61923005: Make NativeTextfieldViews update the win system caret. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix leak, update every time caret is painted Created 7 years, 1 month 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/native_textfield_views.h" 5 #include "ui/views/controls/textfield/native_textfield_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "ui/views/widget/widget.h" 44 #include "ui/views/widget/widget.h"
45 45
46 #if defined(USE_AURA) 46 #if defined(USE_AURA)
47 #include "ui/base/cursor/cursor.h" 47 #include "ui/base/cursor/cursor.h"
48 #endif 48 #endif
49 49
50 #if defined(OS_WIN) && defined(USE_AURA) 50 #if defined(OS_WIN) && defined(USE_AURA)
51 #include "base/win/win_util.h" 51 #include "base/win/win_util.h"
52 #endif 52 #endif
53 53
54 #if defined(OS_WIN)
55 #include "ui/base/win/accessibility_misc_utils.h"
56 #include "ui/views/win/hwnd_util.h"
57 #endif
58
54 namespace { 59 namespace {
55 60
56 void ConvertRectToScreen(const views::View* src, gfx::Rect* r) { 61 void ConvertRectToScreen(const views::View* src, gfx::Rect* r) {
57 DCHECK(src); 62 DCHECK(src);
58 63
59 gfx::Point new_origin = r->origin(); 64 gfx::Point new_origin = r->origin();
60 views::View::ConvertPointToScreen(src, &new_origin); 65 views::View::ConvertPointToScreen(src, &new_origin);
61 r->set_origin(new_origin); 66 r->set_origin(new_origin);
62 } 67 }
63 68
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 void NativeTextfieldViews::HandleBlur() { 695 void NativeTextfieldViews::HandleBlur() {
691 GetRenderText()->set_focused(false); 696 GetRenderText()->set_focused(false);
692 GetInputMethod()->OnBlur(); 697 GetInputMethod()->OnBlur();
693 // Stop blinking cursor. 698 // Stop blinking cursor.
694 cursor_timer_.InvalidateWeakPtrs(); 699 cursor_timer_.InvalidateWeakPtrs();
695 if (is_cursor_visible_) { 700 if (is_cursor_visible_) {
696 is_cursor_visible_ = false; 701 is_cursor_visible_ = false;
697 RepaintCursor(); 702 RepaintCursor();
698 } 703 }
699 704
705 PlatformHideSystemCaret();
706
700 touch_selection_controller_.reset(); 707 touch_selection_controller_.reset();
701 } 708 }
702 709
703 ui::TextInputClient* NativeTextfieldViews::GetTextInputClient() { 710 ui::TextInputClient* NativeTextfieldViews::GetTextInputClient() {
704 return textfield_->read_only() ? NULL : this; 711 return textfield_->read_only() ? NULL : this;
705 } 712 }
706 713
707 void NativeTextfieldViews::ClearEditHistory() { 714 void NativeTextfieldViews::ClearEditHistory() {
708 model_->ClearEditHistory(); 715 model_->ClearEditHistory();
709 } 716 }
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1147 base::Bind(&NativeTextfieldViews::UpdateCursor, 1154 base::Bind(&NativeTextfieldViews::UpdateCursor,
1148 cursor_timer_.GetWeakPtr()), 1155 cursor_timer_.GetWeakPtr()),
1149 base::TimeDelta::FromMilliseconds(caret_blink_ms)); 1156 base::TimeDelta::FromMilliseconds(caret_blink_ms));
1150 } 1157 }
1151 } 1158 }
1152 1159
1153 void NativeTextfieldViews::RepaintCursor() { 1160 void NativeTextfieldViews::RepaintCursor() {
1154 gfx::Rect r(GetRenderText()->GetUpdatedCursorBounds()); 1161 gfx::Rect r(GetRenderText()->GetUpdatedCursorBounds());
1155 r.Inset(-1, -1, -1, -1); 1162 r.Inset(-1, -1, -1, -1);
1156 SchedulePaintInRect(r); 1163 SchedulePaintInRect(r);
1164 PlatformUpdateSystemCaret();
1157 } 1165 }
1158 1166
1159 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { 1167 void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) {
1160 TRACE_EVENT0("views", "NativeTextfieldViews::PaintTextAndCursor"); 1168 TRACE_EVENT0("views", "NativeTextfieldViews::PaintTextAndCursor");
1161 canvas->Save(); 1169 canvas->Save();
1162 GetRenderText()->set_cursor_visible(!is_drop_cursor_visible_ && 1170 GetRenderText()->set_cursor_visible(!is_drop_cursor_visible_ &&
1163 is_cursor_visible_ && !model_->HasSelection()); 1171 is_cursor_visible_ && !model_->HasSelection());
1164 // Draw the text, cursor, and selection. 1172 // Draw the text, cursor, and selection.
1165 GetRenderText()->Draw(canvas); 1173 GetRenderText()->Draw(canvas);
1166 1174
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 1527
1520 if (index != -1) { 1528 if (index != -1) {
1521 obscured_reveal_timer_.Start( 1529 obscured_reveal_timer_.Start(
1522 FROM_HERE, 1530 FROM_HERE,
1523 duration, 1531 duration,
1524 base::Bind(&NativeTextfieldViews::RevealObscuredChar, 1532 base::Bind(&NativeTextfieldViews::RevealObscuredChar,
1525 base::Unretained(this), -1, base::TimeDelta())); 1533 base::Unretained(this), -1, base::TimeDelta()));
1526 } 1534 }
1527 } 1535 }
1528 1536
1537
1538 void NativeTextfieldViews::PlatformUpdateSystemCaret() {
1539 #if defined(OS_WIN)
1540 if (!GetRenderText()->focused())
1541 return;
1542
1543 // Move an invisible system caret to this location for accessibility.
1544 if (!is_drop_cursor_visible_) {
1545 gfx::Rect caret_rect(GetRenderText()->GetUpdatedCursorBounds());
1546 caret_rect = ConvertRectToWidget(caret_rect);
1547 caret_rect += GetWidget()->GetClientAreaBoundsInScreen().OffsetFromOrigin();
1548 if (caret_rect != last_caret_rect_) {
1549 base::win::SetInvisibleSystemCaretRect(HWNDForView(this), caret_rect);
1550 last_caret_rect_ = caret_rect;
1551 }
1552 } else {
1553 DestroyCaret();
1554 last_caret_rect_ = gfx::Rect();
1555 }
1556 #endif
1557 }
1558
1559 void NativeTextfieldViews::PlatformHideSystemCaret() {
1560 #if defined(OS_WIN)
1561 DestroyCaret();
1562 last_caret_rect_ = gfx::Rect();
1563 #endif
1564 }
1565
1529 } // namespace views 1566 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698