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

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

Issue 843023002: [Smart Lock] Add a private API to show an error bubble anchored to the Smart Lock app window. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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
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 <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // readable over it. 83 // readable over it.
84 void SetDisplayedOnBackgroundColor(SkColor color); 84 void SetDisplayedOnBackgroundColor(SkColor color);
85 SkColor displayed_on_background_color() const { 85 SkColor displayed_on_background_color() const {
86 return displayed_on_background_color_; 86 return displayed_on_background_color_;
87 } 87 }
88 88
89 void set_auto_color_readability_enabled(bool auto_color_readability) { 89 void set_auto_color_readability_enabled(bool auto_color_readability) {
90 auto_color_readability_enabled_ = auto_color_readability; 90 auto_color_readability_enabled_ = auto_color_readability;
91 } 91 }
92 92
93 // Resizes the label so its width is set to the width of the longest line and
94 // its height deduced accordingly.
95 // This is only intended for multi-line labels and is useful when the label's
96 // text contains several lines separated with \n.
97 // |max_width| is the maximum width that will be used (longer lines will be
98 // wrapped). If 0, no maximum width is enforced.
99 void SizeToFit(int max_width);
100
93 // View implementation: 101 // View implementation:
94 gfx::Insets GetInsets() const override; 102 gfx::Insets GetInsets() const override;
103 gfx::Size GetPreferredSize() const override;
95 int GetHeightForWidth(int w) const override; 104 int GetHeightForWidth(int w) const override;
96 void Layout() override; 105 void Layout() override;
97 void PreferredSizeChanged() override; 106 void PreferredSizeChanged() override;
98 107
99 // LinkListener implementation: 108 // LinkListener implementation:
100 void LinkClicked(Link* source, int event_flags) override; 109 void LinkClicked(Link* source, int event_flags) override;
101 110
102 private: 111 private:
103 struct StyleRange { 112 struct StyleRange {
104 StyleRange(const gfx::Range& range, 113 StyleRange(const gfx::Range& range,
105 const RangeStyleInfo& style_info) 114 const RangeStyleInfo& style_info)
106 : range(range), 115 : range(range),
107 style_info(style_info) { 116 style_info(style_info) {
108 } 117 }
109 ~StyleRange() {} 118 ~StyleRange() {}
110 119
111 bool operator<(const StyleRange& other) const; 120 bool operator<(const StyleRange& other) const;
112 121
113 gfx::Range range; 122 gfx::Range range;
114 RangeStyleInfo style_info; 123 RangeStyleInfo style_info;
115 }; 124 };
116 typedef std::list<StyleRange> StyleRanges; 125 typedef std::list<StyleRange> StyleRanges;
117 126
118 // Calculates how to layout child views, creates them and sets their size 127 // Calculates how to layout child views, creates them and sets their size and
119 // and position. |width| is the horizontal space, in pixels, that the view 128 // position. |width| is the horizontal space, in pixels, that the view has to
120 // has to work with. If |dry_run| is true, the view hierarchy is not touched. 129 // work with. If |dry_run| is true, the view hierarchy is not touched. Caches
121 // The return value is the necessary size. 130 // the results in |calculated_size_|, |width_at_last_layout_|, and
131 // |width_at_last_size_calculation_|. Returns the needed size.
122 gfx::Size CalculateAndDoLayout(int width, bool dry_run); 132 gfx::Size CalculateAndDoLayout(int width, bool dry_run);
123 133
124 // The text to display. 134 // The text to display.
125 base::string16 text_; 135 base::string16 text_;
126 136
127 // Fonts used to display text. Can be augmented by RangeStyleInfo. 137 // Fonts used to display text. Can be augmented by RangeStyleInfo.
128 gfx::FontList font_list_; 138 gfx::FontList font_list_;
129 139
130 // Line height. 140 // Line height.
131 int specified_line_height_; 141 int specified_line_height_;
132 142
133 // The default style to use for any part of the text that isn't within 143 // The default style to use for any part of the text that isn't within
134 // a range in |style_ranges_|. 144 // a range in |style_ranges_|.
135 RangeStyleInfo default_style_info_; 145 RangeStyleInfo default_style_info_;
136 146
137 // The listener that will be informed of link clicks. 147 // The listener that will be informed of link clicks.
138 StyledLabelListener* listener_; 148 StyledLabelListener* listener_;
139 149
140 // The ranges that should be linkified, sorted by start position. 150 // The ranges that should be linkified, sorted by start position.
141 StyleRanges style_ranges_; 151 StyleRanges style_ranges_;
142 152
143 // A mapping from a view to the range it corresponds to in |text_|. Only views 153 // A mapping from a view to the range it corresponds to in |text_|. Only views
144 // that correspond to ranges with is_link style set will be added to the map. 154 // that correspond to ranges with is_link style set will be added to the map.
145 std::map<View*, gfx::Range> link_targets_; 155 std::map<View*, gfx::Range> link_targets_;
146 156
147 // This variable saves the result of the last GetHeightForWidth call in order 157 // This variable saves the result of the last GetHeightForWidth call in order
148 // to avoid repeated calculation. 158 // to avoid repeated calculation.
149 mutable gfx::Size calculated_size_; 159 mutable gfx::Size calculated_size_;
160 mutable int width_at_last_size_calculation_;
150 int width_at_last_layout_; 161 int width_at_last_layout_;
151 162
152 // Background color on which the label is drawn, for auto color readability. 163 // Background color on which the label is drawn, for auto color readability.
153 SkColor displayed_on_background_color_; 164 SkColor displayed_on_background_color_;
154 bool displayed_on_background_color_set_; 165 bool displayed_on_background_color_set_;
155 166
156 // Controls whether the text is automatically re-colored to be readable on the 167 // Controls whether the text is automatically re-colored to be readable on the
157 // background. 168 // background.
158 bool auto_color_readability_enabled_; 169 bool auto_color_readability_enabled_;
159 170
160 DISALLOW_COPY_AND_ASSIGN(StyledLabel); 171 DISALLOW_COPY_AND_ASSIGN(StyledLabel);
161 }; 172 };
162 173
163 } // namespace views 174 } // namespace views
164 175
165 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_ 176 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698