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/views/controls/text_field.h" | 5 #include "chrome/views/controls/text_field.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlapp.h> | 8 #include <atlapp.h> |
9 #include <atlcrack.h> | 9 #include <atlcrack.h> |
10 #include <atlctrls.h> | 10 #include <atlctrls.h> |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 if (parent_->GetController()) | 872 if (parent_->GetController()) |
873 parent_->GetController()->ContentsChanged(parent_, new_text); | 873 parent_->GetController()->ContentsChanged(parent_, new_text); |
874 } | 874 } |
875 } | 875 } |
876 | 876 |
877 LONG TextField::Edit::ClipXCoordToVisibleText(LONG x, | 877 LONG TextField::Edit::ClipXCoordToVisibleText(LONG x, |
878 bool is_triple_click) const { | 878 bool is_triple_click) const { |
879 // Clip the X coordinate to the left edge of the text. Careful: | 879 // Clip the X coordinate to the left edge of the text. Careful: |
880 // PosFromChar(0) may return a negative X coordinate if the beginning of the | 880 // PosFromChar(0) may return a negative X coordinate if the beginning of the |
881 // text has scrolled off the edit, so don't go past the clip rect's edge. | 881 // text has scrolled off the edit, so don't go past the clip rect's edge. |
| 882 PARAFORMAT2 pf2; |
| 883 GetParaFormat(pf2); |
| 884 // Calculation of the clipped coordinate is more complicated if the paragraph |
| 885 // layout is RTL layout, or if there is RTL characters inside the LTR layout |
| 886 // paragraph. |
| 887 bool ltr_text_in_ltr_layout = true; |
| 888 if ((pf2.wEffects & PFE_RTLPARA) || |
| 889 l10n_util::StringContainsStrongRTLChars(GetText())) { |
| 890 ltr_text_in_ltr_layout = false; |
| 891 } |
| 892 const int length = GetTextLength(); |
882 RECT r; | 893 RECT r; |
883 GetRect(&r); | 894 GetRect(&r); |
884 const int left_bound = std::max(r.left, PosFromChar(0).x); | 895 // The values returned by PosFromChar() seem to refer always |
885 if (x < left_bound) | 896 // to the left edge of the character's bounding box. |
886 return left_bound; | 897 const LONG first_position_x = PosFromChar(0).x; |
| 898 LONG min_x = first_position_x; |
| 899 if (!ltr_text_in_ltr_layout) { |
| 900 for (int i = 1; i < length; ++i) |
| 901 min_x = std::min(min_x, PosFromChar(i).x); |
| 902 } |
| 903 const LONG left_bound = std::max(r.left, min_x); |
887 | 904 |
888 // See if we need to clip to the right edge of the text. | 905 // PosFromChar(length) is a phantom character past the end of the text. It is |
889 const int length = GetTextLength(); | 906 // not necessarily a right bound; in RTL controls it may be a left bound. So |
890 // Asking for the coordinate of any character past the end of the text gets | 907 // treat it as a right bound only if it is to the right of the first |
891 // the pixel just to the right of the last character. | 908 // character. |
892 const int right_bound = std::min(r.right, PosFromChar(length).x); | 909 LONG right_bound = r.right; |
893 if ((length == 0) || (x < right_bound)) | 910 LONG end_position_x = PosFromChar(length).x; |
894 return x; | 911 if (end_position_x >= first_position_x) { |
895 | 912 right_bound = std::min(right_bound, end_position_x); // LTR case. |
| 913 } |
896 // For trailing characters that are 2 pixels wide of less (like "l" in some | 914 // For trailing characters that are 2 pixels wide of less (like "l" in some |
897 // fonts), we have a problem: | 915 // fonts), we have a problem: |
898 // * Clicks on any pixel within the character will place the cursor before | 916 // * Clicks on any pixel within the character will place the cursor before |
899 // the character. | 917 // the character. |
900 // * Clicks on the pixel just after the character will not allow triple- | 918 // * Clicks on the pixel just after the character will not allow triple- |
901 // click to work properly (true for any last character width). | 919 // click to work properly (true for any last character width). |
902 // So, we move to the last pixel of the character when this is a | 920 // So, we move to the last pixel of the character when this is a |
903 // triple-click, and moving to one past the last pixel in all other | 921 // triple-click, and moving to one past the last pixel in all other |
904 // scenarios. This way, all clicks that can move the cursor will place it at | 922 // scenarios. This way, all clicks that can move the cursor will place it at |
905 // the end of the text, but triple-click will still work. | 923 // the end of the text, but triple-click will still work. |
| 924 if (x < left_bound) { |
| 925 return (is_triple_click && ltr_text_in_ltr_layout) ? left_bound - 1 : |
| 926 left_bound; |
| 927 } |
| 928 if ((length == 0) || (x < right_bound)) |
| 929 return x; |
906 return is_triple_click ? (right_bound - 1) : right_bound; | 930 return is_triple_click ? (right_bound - 1) : right_bound; |
907 } | 931 } |
908 | 932 |
909 void TextField::Edit::SetContainsMouse(bool contains_mouse) { | 933 void TextField::Edit::SetContainsMouse(bool contains_mouse) { |
910 if (contains_mouse == contains_mouse_) | 934 if (contains_mouse == contains_mouse_) |
911 return; | 935 return; |
912 | 936 |
913 contains_mouse_ = contains_mouse; | 937 contains_mouse_ = contains_mouse; |
914 | 938 |
915 if (!draw_border_) | 939 if (!draw_border_) |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 | 1179 |
1156 COLORREF bg_color; | 1180 COLORREF bg_color; |
1157 if (!use_default_background_color_) | 1181 if (!use_default_background_color_) |
1158 bg_color = skia::SkColorToCOLORREF(background_color_); | 1182 bg_color = skia::SkColorToCOLORREF(background_color_); |
1159 else | 1183 else |
1160 bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); | 1184 bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); |
1161 edit_->SetBackgroundColor(bg_color); | 1185 edit_->SetBackgroundColor(bg_color); |
1162 } | 1186 } |
1163 | 1187 |
1164 } // namespace views | 1188 } // namespace views |
OLD | NEW |