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

Side by Side Diff: views/controls/label.h

Issue 8113031: Change std::wstring to string16 for views::Label and views::Link (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 2 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 | « chrome/browser/ui/views/wrench_menu.cc ('k') | views/controls/label.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 VIEWS_CONTROLS_LABEL_H_ 5 #ifndef VIEWS_CONTROLS_LABEL_H_
6 #define VIEWS_CONTROLS_LABEL_H_ 6 #define VIEWS_CONTROLS_LABEL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/string16.h"
12 #include "googleurl/src/gurl.h" 13 #include "googleurl/src/gurl.h"
13 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
14 #include "ui/gfx/font.h" 15 #include "ui/gfx/font.h"
15 #include "views/view.h" 16 #include "views/view.h"
16 17
17 namespace views { 18 namespace views {
18 19
19 ///////////////////////////////////////////////////////////////////////////// 20 /////////////////////////////////////////////////////////////////////////////
20 // 21 //
21 // Label class 22 // Label class
(...skipping 23 matching lines...) Expand all
45 AUTO_DETECT_ALIGNMENT 46 AUTO_DETECT_ALIGNMENT
46 }; 47 };
47 48
48 // The view class name. 49 // The view class name.
49 static const char kViewClassName[]; 50 static const char kViewClassName[];
50 51
51 // The padding for the focus border when rendering focused text. 52 // The padding for the focus border when rendering focused text.
52 static const int kFocusBorderPadding; 53 static const int kFocusBorderPadding;
53 54
54 Label(); 55 Label();
55 explicit Label(const std::wstring& text); 56 explicit Label(const string16& text);
56 Label(const std::wstring& text, const gfx::Font& font); 57 Label(const string16& text, const gfx::Font& font);
57 virtual ~Label(); 58 virtual ~Label();
58 59
59 // Set the font. 60 // Set the font.
60 virtual void SetFont(const gfx::Font& font); 61 virtual void SetFont(const gfx::Font& font);
61 62
62 // Set the label text. 63 // Set the label text.
63 void SetText(const std::wstring& text); 64 void SetText(const string16& text);
64 65
65 // Return the font used by this label. 66 // Return the font used by this label.
66 gfx::Font font() const { return font_; } 67 gfx::Font font() const { return font_; }
67 68
68 // Return the label text. 69 // Return the label text.
69 const std::wstring GetText() const; 70 const string16 GetText() const;
70 71
71 // Set URL Value - text_ is set to spec(). 72 // Set URL Value - text_ is set to spec().
72 void SetURL(const GURL& url); 73 void SetURL(const GURL& url);
73 74
74 // Return the label URL. 75 // Return the label URL.
75 const GURL GetURL() const; 76 const GURL GetURL() const;
76 77
77 // Set the color 78 // Set the color
78 virtual void SetColor(const SkColor& color); 79 virtual void SetColor(const SkColor& color);
79 80
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // Gets the tooltip text for labels that are wider than their bounds, except 176 // Gets the tooltip text for labels that are wider than their bounds, except
176 // when the label is multiline, in which case it just returns false (no 177 // when the label is multiline, in which case it just returns false (no
177 // tooltip). If a custom tooltip has been specified with SetTooltipText() 178 // tooltip). If a custom tooltip has been specified with SetTooltipText()
178 // it is returned instead. 179 // it is returned instead.
179 virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE; 180 virtual bool GetTooltipText(const gfx::Point& p, string16* tooltip) OVERRIDE;
180 181
181 protected: 182 protected:
182 // Called by Paint to paint the text. Override this to change how 183 // Called by Paint to paint the text. Override this to change how
183 // text is painted. 184 // text is painted.
184 virtual void PaintText(gfx::Canvas* canvas, 185 virtual void PaintText(gfx::Canvas* canvas,
185 const std::wstring& text, 186 const string16& text,
186 const gfx::Rect& text_bounds, 187 const gfx::Rect& text_bounds,
187 int flags); 188 int flags);
188 189
189 void invalidate_text_size() { text_size_valid_ = false; } 190 void invalidate_text_size() { text_size_valid_ = false; }
190 191
191 virtual gfx::Size GetTextSize() const; 192 virtual gfx::Size GetTextSize() const;
192 193
193 // Overridden from View: 194 // Overridden from View:
194 // Overridden to dirty our text bounds if we're multi-line. 195 // Overridden to dirty our text bounds if we're multi-line.
195 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; 196 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
196 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 197 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
197 // If the mouse is over the label, and a mouse over background has been 198 // If the mouse is over the label, and a mouse over background has been
198 // specified, its used. Otherwise super's implementation is invoked. 199 // specified, its used. Otherwise super's implementation is invoked.
199 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; 200 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
200 201
201 private: 202 private:
202 // These tests call CalculateDrawStringParams in order to verify the 203 // These tests call CalculateDrawStringParams in order to verify the
203 // calculations done for drawing text. 204 // calculations done for drawing text.
204 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString); 205 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineString);
205 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString); 206 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineString);
206 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL); 207 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawSingleLineStringInRTL);
207 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL); 208 FRIEND_TEST_ALL_PREFIXES(LabelTest, DrawMultiLineStringInRTL);
208 209
209 static gfx::Font GetDefaultFont(); 210 static gfx::Font GetDefaultFont();
210 211
211 void Init(const std::wstring& text, const gfx::Font& font); 212 void Init(const string16& text, const gfx::Font& font);
212 213
213 // If the mouse is over the text, SetContainsMouse(true) is invoked, otherwise 214 // If the mouse is over the text, SetContainsMouse(true) is invoked, otherwise
214 // SetContainsMouse(false) is invoked. 215 // SetContainsMouse(false) is invoked.
215 void UpdateContainsMouse(const MouseEvent& event); 216 void UpdateContainsMouse(const MouseEvent& event);
216 217
217 // Updates whether the mouse is contained in the Label. If the new value 218 // Updates whether the mouse is contained in the Label. If the new value
218 // differs from the current value, and a mouse over background is specified, 219 // differs from the current value, and a mouse over background is specified,
219 // SchedulePaint is invoked. 220 // SchedulePaint is invoked.
220 void SetContainsMouse(bool contains_mouse); 221 void SetContainsMouse(bool contains_mouse);
221 222
222 // Returns where the text is drawn, in the receivers coordinate system. 223 // Returns where the text is drawn, in the receivers coordinate system.
223 gfx::Rect GetTextBounds() const; 224 gfx::Rect GetTextBounds() const;
224 225
225 int ComputeMultiLineFlags() const; 226 int ComputeMultiLineFlags() const;
226 227
227 gfx::Rect GetAvailableRect() const; 228 gfx::Rect GetAvailableRect() const;
228 229
229 // Returns parameters to be used for the DrawString call. 230 // Returns parameters to be used for the DrawString call.
230 void CalculateDrawStringParams(std::wstring* paint_text, 231 void CalculateDrawStringParams(string16* paint_text,
231 gfx::Rect* text_bounds, 232 gfx::Rect* text_bounds,
232 int* flags) const; 233 int* flags) const;
233 234
234 string16 text_; 235 string16 text_;
235 GURL url_; 236 GURL url_;
236 gfx::Font font_; 237 gfx::Font font_;
237 SkColor color_; 238 SkColor color_;
238 mutable gfx::Size text_size_; 239 mutable gfx::Size text_size_;
239 mutable bool text_size_valid_; 240 mutable bool text_size_valid_;
240 bool is_multi_line_; 241 bool is_multi_line_;
(...skipping 18 matching lines...) Expand all
259 // allows this view to reserve space for a focus border that it otherwise 260 // allows this view to reserve space for a focus border that it otherwise
260 // might not have because it is not itself focusable. 261 // might not have because it is not itself focusable.
261 bool has_focus_border_; 262 bool has_focus_border_;
262 263
263 DISALLOW_COPY_AND_ASSIGN(Label); 264 DISALLOW_COPY_AND_ASSIGN(Label);
264 }; 265 };
265 266
266 } // namespace views 267 } // namespace views
267 268
268 #endif // VIEWS_CONTROLS_LABEL_H_ 269 #endif // VIEWS_CONTROLS_LABEL_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/wrench_menu.cc ('k') | views/controls/label.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698