OLD | NEW |
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 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1828 } | 1828 } |
1829 | 1829 |
1830 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const { | 1830 bool AutocompleteEditViewWin::IsSelectAllForRange(const CHARRANGE& sel) const { |
1831 const int text_length = GetTextLength(); | 1831 const int text_length = GetTextLength(); |
1832 return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) || | 1832 return ((sel.cpMin == 0) && (sel.cpMax >= text_length)) || |
1833 ((sel.cpMax == 0) && (sel.cpMin >= text_length)); | 1833 ((sel.cpMax == 0) && (sel.cpMin >= text_length)); |
1834 } | 1834 } |
1835 | 1835 |
1836 LONG AutocompleteEditViewWin::ClipXCoordToVisibleText( | 1836 LONG AutocompleteEditViewWin::ClipXCoordToVisibleText( |
1837 LONG x, bool is_triple_click) const { | 1837 LONG x, bool is_triple_click) const { |
1838 // Clip the X coordinate to the left edge of the text. Careful: | 1838 // Clip the X coordinate to the left edge of the text. Careful: |
1839 // PosFromChar(0) may return a negative X coordinate if the beginning of the | 1839 // PosFromChar(0) may return a negative X coordinate if the beginning of the |
1840 // text has scrolled off the edit, so don't go past the clip rect's edge. | 1840 // text has scrolled off the edit, so don't go past the clip rect's edge. |
| 1841 PARAFORMAT2 pf2; |
| 1842 GetParaFormat(pf2); |
| 1843 // Calculation of the clipped coordinate is more complicated if the paragraph |
| 1844 // layout is RTL layout, or if there is RTL characters inside the LTR layout |
| 1845 // paragraph. |
| 1846 bool ltr_text_in_ltr_layout = true; |
| 1847 if ((pf2.wEffects & PFE_RTLPARA) || |
| 1848 l10n_util::StringContainsStrongRTLChars(GetText())) { |
| 1849 ltr_text_in_ltr_layout = false; |
| 1850 } |
| 1851 const int length = GetTextLength(); |
1841 RECT r; | 1852 RECT r; |
1842 GetRect(&r); | 1853 GetRect(&r); |
1843 const int left_bound = std::max(r.left, PosFromChar(0).x); | 1854 // The values returned by PosFromChar() seem to refer always |
1844 if (x < left_bound) | 1855 // to the left edge of the character's bounding box. |
1845 return left_bound; | 1856 const LONG first_position_x = PosFromChar(0).x; |
1846 | 1857 LONG min_x = first_position_x; |
1847 // See if we need to clip to the right edge of the text. | 1858 if (!ltr_text_in_ltr_layout) { |
1848 const int length = GetTextLength(); | 1859 for (int i = 1; i < length; ++i) |
1849 // Asking for the coordinate of any character past the end of the text gets | 1860 min_x = std::min(min_x, PosFromChar(i).x); |
1850 // the pixel just to the right of the last character. | 1861 } |
1851 const int right_bound = std::min(r.right, PosFromChar(length).x); | 1862 const LONG left_bound = std::max(r.left, min_x); |
1852 if ((length == 0) || (x < right_bound)) | 1863 // PosFromChar(length) is a phantom character past the end of the text. It is |
1853 return x; | 1864 // not necessarily a right bound; in RTL controls it may be a left bound. So |
1854 | 1865 // treat it as a right bound only if it is to the right of the first |
| 1866 // character. |
| 1867 LONG right_bound = r.right; |
| 1868 LONG end_position_x = PosFromChar(length).x; |
| 1869 if (end_position_x >= first_position_x) { |
| 1870 right_bound = std::min(right_bound, end_position_x); // LTR case. |
| 1871 } |
1855 // For trailing characters that are 2 pixels wide of less (like "l" in some | 1872 // For trailing characters that are 2 pixels wide of less (like "l" in some |
1856 // fonts), we have a problem: | 1873 // fonts), we have a problem: |
1857 // * Clicks on any pixel within the character will place the cursor before | 1874 // * Clicks on any pixel within the character will place the cursor before |
1858 // the character. | 1875 // the character. |
1859 // * Clicks on the pixel just after the character will not allow triple- | 1876 // * Clicks on the pixel just after the character will not allow triple- |
1860 // click to work properly (true for any last character width). | 1877 // click to work properly (true for any last character width). |
1861 // So, we move to the last pixel of the character when this is a | 1878 // So, we move to the last pixel of the character when this is a |
1862 // triple-click, and moving to one past the last pixel in all other | 1879 // triple-click, and moving to one past the last pixel in all other |
1863 // scenarios. This way, all clicks that can move the cursor will place it at | 1880 // scenarios. This way, all clicks that can move the cursor will place it at |
1864 // the end of the text, but triple-click will still work. | 1881 // the end of the text, but triple-click will still work. |
| 1882 if (x < left_bound) { |
| 1883 return (is_triple_click && ltr_text_in_ltr_layout) ? left_bound - 1 : |
| 1884 left_bound; |
| 1885 } |
| 1886 if ((length == 0) || (x < right_bound)) |
| 1887 return x; |
1865 return is_triple_click ? (right_bound - 1) : right_bound; | 1888 return is_triple_click ? (right_bound - 1) : right_bound; |
1866 } | 1889 } |
1867 | 1890 |
1868 void AutocompleteEditViewWin::EmphasizeURLComponents() { | 1891 void AutocompleteEditViewWin::EmphasizeURLComponents() { |
1869 ITextDocument* const text_object_model = GetTextObjectModel(); | 1892 ITextDocument* const text_object_model = GetTextObjectModel(); |
1870 ScopedFreeze freeze(this, text_object_model); | 1893 ScopedFreeze freeze(this, text_object_model); |
1871 ScopedSuspendUndo suspend_undo(text_object_model); | 1894 ScopedSuspendUndo suspend_undo(text_object_model); |
1872 | 1895 |
1873 // Save the selection. | 1896 // Save the selection. |
1874 CHARRANGE saved_sel; | 1897 CHARRANGE saved_sel; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2219 } | 2242 } |
2220 | 2243 |
2221 void AutocompleteEditViewWin::RepaintDropHighlight(int position) { | 2244 void AutocompleteEditViewWin::RepaintDropHighlight(int position) { |
2222 if ((position != -1) && (position <= GetTextLength())) { | 2245 if ((position != -1) && (position <= GetTextLength())) { |
2223 const POINT min_loc(PosFromChar(position)); | 2246 const POINT min_loc(PosFromChar(position)); |
2224 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, | 2247 const RECT highlight_bounds = {min_loc.x - 1, font_y_adjustment_, |
2225 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_}; | 2248 min_loc.x + 2, font_ascent_ + font_descent_ + font_y_adjustment_}; |
2226 InvalidateRect(&highlight_bounds, false); | 2249 InvalidateRect(&highlight_bounds, false); |
2227 } | 2250 } |
2228 } | 2251 } |
OLD | NEW |