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

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

Issue 111023004: Add GetMinimumSize() for Labels and ensure it's zero for empty Links. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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 <list>
8 #include <map> 9 #include <map>
9 #include <queue>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/strings/string16.h" 12 #include "base/strings/string16.h"
13 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
14 #include "ui/gfx/range/range.h" 14 #include "ui/gfx/range/range.h"
15 #include "ui/gfx/size.h" 15 #include "ui/gfx/size.h"
16 #include "ui/views/controls/link_listener.h" 16 #include "ui/views/controls/link_listener.h"
17 #include "ui/views/view.h" 17 #include "ui/views/view.h"
18 18
19 namespace views { 19 namespace views {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 void set_auto_color_readability_enabled(bool auto_color_readability) { 79 void set_auto_color_readability_enabled(bool auto_color_readability) {
80 auto_color_readability_enabled_ = auto_color_readability; 80 auto_color_readability_enabled_ = auto_color_readability;
81 } 81 }
82 82
83 // View implementation: 83 // View implementation:
84 virtual gfx::Insets GetInsets() const OVERRIDE; 84 virtual gfx::Insets GetInsets() const OVERRIDE;
85 virtual int GetHeightForWidth(int w) OVERRIDE; 85 virtual int GetHeightForWidth(int w) OVERRIDE;
86 virtual void Layout() OVERRIDE; 86 virtual void Layout() OVERRIDE;
87 virtual void PreferredSizeChanged() OVERRIDE; 87 virtual void PreferredSizeChanged() OVERRIDE;
88 virtual void ViewHierarchyChanged(
89 const ViewHierarchyChangedDetails& details) OVERRIDE;
90 virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE;
88 91
89 // LinkListener implementation: 92 // LinkListener implementation:
90 virtual void LinkClicked(Link* source, int event_flags) OVERRIDE; 93 virtual void LinkClicked(Link* source, int event_flags) OVERRIDE;
91 94
92 private: 95 private:
93 struct StyleRange { 96 struct StyleRange {
94 StyleRange(const gfx::Range& range, 97 StyleRange(const gfx::Range& range,
95 const RangeStyleInfo& style_info) 98 const RangeStyleInfo& style_info)
96 : range(range), 99 : range(range),
97 style_info(style_info) { 100 style_info(style_info) {
98 } 101 }
99 ~StyleRange() {} 102 ~StyleRange() {}
100 103
101 bool operator<(const StyleRange& other) const; 104 bool operator<(const StyleRange& other) const;
102 105
103 gfx::Range range; 106 gfx::Range range;
104 RangeStyleInfo style_info; 107 RangeStyleInfo style_info;
105 }; 108 };
109 typedef std::list<StyleRange> StyleRanges;
106 110
107 // Calculates how to layout child views, creates them and sets their size 111 // Calculates how to layout child views, creates them and sets their size
108 // and position. |width| is the horizontal space, in pixels, that the view 112 // and position. |width| is the horizontal space, in pixels, that the view
109 // has to work with. If |dry_run| is true, the view hierarchy is not touched. 113 // has to work with. If |dry_run| is true, the view hierarchy is not touched.
110 // The return value is the height in pixels. 114 // The return value is the necessary size.
111 int CalculateAndDoLayout(int width, bool dry_run); 115 gfx::Size CalculateAndDoLayout(int width, bool dry_run);
112 116
113 // The text to display. 117 // The text to display.
114 string16 text_; 118 string16 text_;
115 119
116 // The default style to use for any part of the text that isn't within 120 // The default style to use for any part of the text that isn't within
117 // a range in |style_ranges_|. 121 // a range in |style_ranges_|.
118 RangeStyleInfo default_style_info_; 122 RangeStyleInfo default_style_info_;
119 123
120 // The listener that will be informed of link clicks. 124 // The listener that will be informed of link clicks.
121 StyledLabelListener* listener_; 125 StyledLabelListener* listener_;
122 126
123 // The ranges that should be linkified, sorted by start position. 127 // The ranges that should be linkified, sorted by start position.
124 std::priority_queue<StyleRange> style_ranges_; 128 StyleRanges style_ranges_;
125 129
126 // A mapping from a view to the range it corresponds to in |text_|. Only views 130 // A mapping from a view to the range it corresponds to in |text_|. Only views
127 // that correspond to ranges with is_link style set will be added to the map. 131 // that correspond to ranges with is_link style set will be added to the map.
128 std::map<View*, gfx::Range> link_targets_; 132 std::map<View*, gfx::Range> link_targets_;
129 133
130 // This variable saves the result of the last GetHeightForWidth call in order 134 // This variable saves the result of the last GetHeightForWidth call in order
131 // to avoid repeated calculation. 135 // to avoid repeated calculation.
132 gfx::Size calculated_size_; 136 gfx::Size calculated_size_;
133 137
138 // Saves the most recent value of IsDrawn() as of the last call to
139 // GetInsets(), since if this changes, we may need to recalulate our size.
140 mutable bool is_drawn_;
141
134 // Background color on which the label is drawn, for auto color readability. 142 // Background color on which the label is drawn, for auto color readability.
135 SkColor displayed_on_background_color_; 143 SkColor displayed_on_background_color_;
136 bool displayed_on_background_color_set_; 144 bool displayed_on_background_color_set_;
137 145
138 // Controls whether the text is automatically re-colored to be readable on the 146 // Controls whether the text is automatically re-colored to be readable on the
139 // background. 147 // background.
140 bool auto_color_readability_enabled_; 148 bool auto_color_readability_enabled_;
141 149
142 DISALLOW_COPY_AND_ASSIGN(StyledLabel); 150 DISALLOW_COPY_AND_ASSIGN(StyledLabel);
143 }; 151 };
144 152
145 } // namespace views 153 } // namespace views
146 154
147 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_ 155 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698