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

Side by Side Diff: ui/views/controls/styled_label.h

Issue 19531006: requestAutocomplete: fix some text colors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: +PreferredSizeChanged override Created 7 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 #ifndef UI_VIEWS_CONTROLS_STYLED_LABEL_H_ 5 #ifndef UI_VIEWS_CONTROLS_STYLED_LABEL_H_
6 #define UI_VIEWS_CONTROLS_STYLED_LABEL_H_ 6 #define UI_VIEWS_CONTROLS_STYLED_LABEL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 StyledLabel(const string16& text, StyledLabelListener* listener); 57 StyledLabel(const string16& text, StyledLabelListener* listener);
58 virtual ~StyledLabel(); 58 virtual ~StyledLabel();
59 59
60 // Sets the text to be displayed, and clears any previous styling. 60 // Sets the text to be displayed, and clears any previous styling.
61 void SetText(const string16& text); 61 void SetText(const string16& text);
62 62
63 // Marks the given range within |text_| with style defined by |style_info|. 63 // Marks the given range within |text_| with style defined by |style_info|.
64 // |range| must be contained in |text_|. 64 // |range| must be contained in |text_|.
65 void AddStyleRange(const ui::Range& range, const RangeStyleInfo& style_info); 65 void AddStyleRange(const ui::Range& range, const RangeStyleInfo& style_info);
66 66
67 // Sets the default style to use for any part of the text that isn't within
68 // a range set by AddStyleRange.
69 void SetDefaultStyle(const RangeStyleInfo& style_info);
70
67 // Sets the color of the background on which the label is drawn. This won't 71 // Sets the color of the background on which the label is drawn. This won't
68 // be explicitly drawn, but the label will force the text color to be 72 // be explicitly drawn, but the label will force the text color to be
69 // readable over it. 73 // readable over it.
70 void SetDisplayedOnBackgroundColor(SkColor color); 74 void SetDisplayedOnBackgroundColor(SkColor color);
71 SkColor displayed_on_background_color() const { 75 SkColor displayed_on_background_color() const {
72 return displayed_on_background_color_; 76 return displayed_on_background_color_;
73 } 77 }
74 78
75 // View implementation: 79 // View implementation:
76 virtual gfx::Insets GetInsets() const OVERRIDE; 80 virtual gfx::Insets GetInsets() const OVERRIDE;
77 virtual int GetHeightForWidth(int w) OVERRIDE; 81 virtual int GetHeightForWidth(int w) OVERRIDE;
78 virtual void Layout() OVERRIDE; 82 virtual void Layout() OVERRIDE;
83 virtual void PreferredSizeChanged() OVERRIDE;
79 84
80 // LinkListener implementation: 85 // LinkListener implementation:
81 virtual void LinkClicked(Link* source, int event_flags) OVERRIDE; 86 virtual void LinkClicked(Link* source, int event_flags) OVERRIDE;
82 87
83 private: 88 private:
84 struct StyleRange { 89 struct StyleRange {
85 StyleRange(const ui::Range& range, 90 StyleRange(const ui::Range& range,
86 const RangeStyleInfo& style_info) 91 const RangeStyleInfo& style_info)
87 : range(range), 92 : range(range),
88 style_info(style_info) { 93 style_info(style_info) {
89 } 94 }
90 ~StyleRange() {} 95 ~StyleRange() {}
91 96
92 bool operator<(const StyleRange& other) const; 97 bool operator<(const StyleRange& other) const;
93 98
94 ui::Range range; 99 ui::Range range;
95 RangeStyleInfo style_info; 100 RangeStyleInfo style_info;
96 }; 101 };
97 102
98 // Calculates how to layout child views, creates them and sets their size 103 // Calculates how to layout child views, creates them and sets their size
99 // and position. |width| is the horizontal space, in pixels, that the view 104 // and position. |width| is the horizontal space, in pixels, that the view
100 // has to work with. If |dry_run| is true, the view hierarchy is not touched. 105 // has to work with. If |dry_run| is true, the view hierarchy is not touched.
101 // The return value is the height in pixels. 106 // The return value is the height in pixels.
102 int CalculateAndDoLayout(int width, bool dry_run); 107 int CalculateAndDoLayout(int width, bool dry_run);
103 108
104 // The text to display. 109 // The text to display.
105 string16 text_; 110 string16 text_;
106 111
112 // The default style to use for any part of the text that isn't within
113 // a range in |style_ranges_|.
114 RangeStyleInfo default_style_info_;
115
107 // The listener that will be informed of link clicks. 116 // The listener that will be informed of link clicks.
108 StyledLabelListener* listener_; 117 StyledLabelListener* listener_;
109 118
110 // The ranges that should be linkified, sorted by start position. 119 // The ranges that should be linkified, sorted by start position.
111 std::priority_queue<StyleRange> style_ranges_; 120 std::priority_queue<StyleRange> style_ranges_;
112 121
113 // A mapping from a view to the range it corresponds to in |text_|. Only views 122 // A mapping from a view to the range it corresponds to in |text_|. Only views
114 // that correspond to ranges with is_link style set will be added to the map. 123 // that correspond to ranges with is_link style set will be added to the map.
115 std::map<View*, ui::Range> link_targets_; 124 std::map<View*, ui::Range> link_targets_;
116 125
117 // This variable saves the result of the last GetHeightForWidth call in order 126 // This variable saves the result of the last GetHeightForWidth call in order
118 // to avoid repeated calculation. 127 // to avoid repeated calculation.
119 gfx::Size calculated_size_; 128 gfx::Size calculated_size_;
120 129
121 // Background color on which the label is drawn, for auto color readability. 130 // Background color on which the label is drawn, for auto color readability.
122 SkColor displayed_on_background_color_; 131 SkColor displayed_on_background_color_;
123 bool displayed_on_background_color_set_; 132 bool displayed_on_background_color_set_;
124 133
125 DISALLOW_COPY_AND_ASSIGN(StyledLabel); 134 DISALLOW_COPY_AND_ASSIGN(StyledLabel);
126 }; 135 };
127 136
128 } // namespace views 137 } // namespace views
129 138
130 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_ 139 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc ('k') | ui/views/controls/styled_label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698