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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_win.cc

Issue 86003: Review Rquest: fix 6125 and 8686 -- cursor positioning in CRichEditCtrl (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/views/controls/text_field.cc » ('j') | 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/autocomplete/autocomplete_edit_view_win.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_win.h"
6 6
7 #include <locale> 7 #include <locale>
8 8
9 #include "base/base_drag_source.h" 9 #include "base/base_drag_source.h"
10 #include "base/base_drop_target.h" 10 #include "base/base_drop_target.h"
(...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after
1834 } 1834 }
1835 1835
1836 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const { 1836 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const {
1837 const int text_length = GetTextLength(); 1837 const int text_length = GetTextLength();
1838 return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) || 1838 return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) ||
1839 ((sel.cpMax == 0) && (sel.cpMin >= text_length)); 1839 ((sel.cpMax == 0) && (sel.cpMin >= text_length));
1840 } 1840 }
1841 1841
1842 LONG AutocompleteEditViewWin::ClipXCoordToVisibleText( 1842 LONG AutocompleteEditViewWin::ClipXCoordToVisibleText(
1843 LONG x, bool is_triple_click) const { 1843 LONG x, bool is_triple_click) const {
1844 // Clip the X coordinate to the left edge of the text. Careful: 1844 // Clip the X coordinate to the left edge of the text. Careful:
1845 // PosFromChar(0) may return a negative X coordinate if the beginning of the 1845 // PosFromChar(0) may return a negative X coordinate if the beginning of the
1846 // text has scrolled off the edit, so don't go past the clip rect's edge. 1846 // text has scrolled off the edit, so don't go past the clip rect's edge.
1847 PARAFORMAT2 pf2;
1848 GetParaFormat(pf2);
1849 // Calculation of the clipped coordinate is more complicated if the paragraph
1850 // layout is RTL layout, or if there is RTL characters inside the LTR layout
1851 // paragraph.
1852 bool ltr_text_in_ltr_layout = true;
1853 if ((pf2.wEffects & PFE_RTLPARA) ||
1854 l10n_util::StringContainsStrongRTLChars(GetText())) {
1855 ltr_text_in_ltr_layout = false;
1856 }
1857 const int length = GetTextLength();
1847 RECT r; 1858 RECT r;
1848 GetRect(&r); 1859 GetRect(&r);
1849 const int left_bound = std::max(r.left, PosFromChar(0).x); 1860 // The values returned by PosFromChar() seem to refer always
1850 if (x < left_bound) 1861 // to the left edge of the character's bounding box.
1851 return left_bound; 1862 const LONG first_position_x = PosFromChar(0).x;
1852 1863 LONG min_x = first_position_x;
1853 // See if we need to clip to the right edge of the text. 1864 if (!ltr_text_in_ltr_layout) {
1854 const int length = GetTextLength(); 1865 for (int i = 1; i < length; ++i)
1855 // Asking for the coordinate of any character past the end of the text gets 1866 min_x = std::min(min_x, PosFromChar(i).x);
1856 // the pixel just to the right of the last character. 1867 }
1857 const int right_bound = std::min(r.right, PosFromChar(length).x); 1868 const LONG left_bound = std::max(r.left, min_x);
1858 if ((length == 0) || (x < right_bound)) 1869 // PosFromChar(length) is a phantom character past the end of the text. It is
1859 return x; 1870 // not necessarily a right bound; in RTL controls it may be a left bound. So
1860 1871 // treat it as a right bound only if it is to the right of the first
1872 // character.
1873 LONG right_bound = r.right;
1874 LONG end_position_x = PosFromChar(length).x;
1875 if (end_position_x >= first_position_x) {
1876 right_bound = std::min(right_bound, end_position_x); // LTR case.
1877 }
1861 // For trailing characters that are 2 pixels wide of less (like "l" in some 1878 // For trailing characters that are 2 pixels wide of less (like "l" in some
1862 // fonts), we have a problem: 1879 // fonts), we have a problem:
1863 // * Clicks on any pixel within the character will place the cursor before 1880 // * Clicks on any pixel within the character will place the cursor before
1864 // the character. 1881 // the character.
1865 // * Clicks on the pixel just after the character will not allow triple- 1882 // * Clicks on the pixel just after the character will not allow triple-
1866 // click to work properly (true for any last character width). 1883 // click to work properly (true for any last character width).
1867 // So, we move to the last pixel of the character when this is a 1884 // So, we move to the last pixel of the character when this is a
1868 // triple-click, and moving to one past the last pixel in all other 1885 // triple-click, and moving to one past the last pixel in all other
1869 // scenarios. This way, all clicks that can move the cursor will place it at 1886 // scenarios. This way, all clicks that can move the cursor will place it at
1870 // the end of the text, but triple-click will still work. 1887 // the end of the text, but triple-click will still work.
1888 if (x < left_bound) {
1889 return (is_triple_click && ltr_text_in_ltr_layout) ? left_bound - 1 :
1890 left_bound;
1891 }
1892 if ((length == 0) || (x < right_bound))
1893 return x;
1871 return is_triple_click ? (right_bound - 1) : right_bound; 1894 return is_triple_click ? (right_bound - 1) : right_bound;
1872 } 1895 }
1873 1896
1874 void AutocompleteEditViewWin::EmphasizeURLComponents() { 1897 void AutocompleteEditViewWin::EmphasizeURLComponents() {
1875 ITextDocument* const text_object_model = GetTextObjectModel(); 1898 ITextDocument* const text_object_model = GetTextObjectModel();
1876 ScopedFreeze freeze(this, text_object_model); 1899 ScopedFreeze freeze(this, text_object_model);
1877 ScopedSuspendUndo suspend_undo(text_object_model); 1900 ScopedSuspendUndo suspend_undo(text_object_model);
1878 1901
1879 // Save the selection. 1902 // Save the selection.
1880 CHARRANGE saved_sel; 1903 CHARRANGE saved_sel;
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2226 } 2249 }
2227 2250
2228 void AutocompleteEditViewWin::RepaintDropHighlight(int position) { 2251 void AutocompleteEditViewWin::RepaintDropHighlight(int position) {
2229 if ((position != -1) && (position <= GetTextLength())) { 2252 if ((position != -1) && (position <= GetTextLength())) {
2230 const POINT min_loc(PosFromChar(position)); 2253 const POINT min_loc(PosFromChar(position));
2231 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, 2254 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_,
2232 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_}; 2255 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_};
2233 InvalidateRect(&highlight_bounds, false); 2256 InvalidateRect(&highlight_bounds, false);
2234 } 2257 }
2235 } 2258 }
OLDNEW
« no previous file with comments | « no previous file | chrome/views/controls/text_field.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698