| OLD | NEW |
| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 void SetText(const base::string16& text); | 66 void SetText(const base::string16& text); |
| 67 | 67 |
| 68 // Sets the fonts used by all labels. Can be augemented by styling set by | 68 // Sets the fonts used by all labels. Can be augemented by styling set by |
| 69 // AddStyleRange and SetDefaultStyle. | 69 // AddStyleRange and SetDefaultStyle. |
| 70 void SetBaseFontList(const gfx::FontList& font_list); | 70 void SetBaseFontList(const gfx::FontList& font_list); |
| 71 | 71 |
| 72 // Marks the given range within |text_| with style defined by |style_info|. | 72 // Marks the given range within |text_| with style defined by |style_info|. |
| 73 // |range| must be contained in |text_|. | 73 // |range| must be contained in |text_|. |
| 74 void AddStyleRange(const gfx::Range& range, const RangeStyleInfo& style_info); | 74 void AddStyleRange(const gfx::Range& range, const RangeStyleInfo& style_info); |
| 75 | 75 |
| 76 // Inserts a |view| into the given |position| within |text_|. |position| must |
| 77 // be contained in |text_|. Takes ownership of |view| (which should not |
| 78 // already be parented within the views hierarchy). |
| 79 void AddEmbeddedView(uint32_t position, scoped_ptr<View> view); |
| 80 |
| 76 // Sets the default style to use for any part of the text that isn't within | 81 // Sets the default style to use for any part of the text that isn't within |
| 77 // a range set by AddStyleRange. | 82 // a range set by AddStyleRange. |
| 78 void SetDefaultStyle(const RangeStyleInfo& style_info); | 83 void SetDefaultStyle(const RangeStyleInfo& style_info); |
| 79 | 84 |
| 80 // Get or set the distance in pixels between baselines of multi-line text. | 85 // Get or set the distance in pixels between baselines of multi-line text. |
| 81 // Default is 0, indicating the distance between lines should be the standard | 86 // Default is 0, indicating the distance between lines should be the standard |
| 82 // one for the label's text, font list, and platform. | 87 // one for the label's text, font list, and platform. |
| 83 void SetLineHeight(int height); | 88 void SetLineHeight(int height); |
| 84 | 89 |
| 85 // Sets the color of the background on which the label is drawn. This won't | 90 // Sets the color of the background on which the label is drawn. This won't |
| (...skipping 23 matching lines...) Expand all Loading... |
| 109 int GetHeightForWidth(int w) const override; | 114 int GetHeightForWidth(int w) const override; |
| 110 void Layout() override; | 115 void Layout() override; |
| 111 void PreferredSizeChanged() override; | 116 void PreferredSizeChanged() override; |
| 112 | 117 |
| 113 // LinkListener implementation: | 118 // LinkListener implementation: |
| 114 void LinkClicked(Link* source, int event_flags) override; | 119 void LinkClicked(Link* source, int event_flags) override; |
| 115 | 120 |
| 116 private: | 121 private: |
| 117 struct StyleRange { | 122 struct StyleRange { |
| 118 StyleRange(const gfx::Range& range, | 123 StyleRange(const gfx::Range& range, |
| 119 const RangeStyleInfo& style_info) | 124 const RangeStyleInfo& style_info, |
| 120 : range(range), | 125 View* embedded_view) |
| 121 style_info(style_info) { | 126 : range(range), style_info(style_info), embedded_view(embedded_view) {} |
| 122 } | |
| 123 ~StyleRange() {} | 127 ~StyleRange() {} |
| 124 | 128 |
| 125 bool operator<(const StyleRange& other) const; | 129 bool operator<(const StyleRange& other) const; |
| 126 | 130 |
| 127 gfx::Range range; | 131 gfx::Range range; |
| 128 RangeStyleInfo style_info; | 132 RangeStyleInfo style_info; |
| 133 // Pointer to an element of |embedded_views_|. Can be null. If non-null, the |
| 134 // text range is replaced by the embedded view and |style_info| is ignored. |
| 135 View* embedded_view; |
| 129 }; | 136 }; |
| 130 typedef std::list<StyleRange> StyleRanges; | 137 typedef std::list<StyleRange> StyleRanges; |
| 131 | 138 |
| 132 // Calculates how to layout child views, creates them and sets their size and | 139 // Calculates how to layout child views, creates them and sets their size and |
| 133 // position. |width| is the horizontal space, in pixels, that the view has to | 140 // position. |width| is the horizontal space, in pixels, that the view has to |
| 134 // work with. If |dry_run| is true, the view hierarchy is not touched. Caches | 141 // work with. If |dry_run| is true, the view hierarchy is not touched. Caches |
| 135 // the results in |calculated_size_|, |width_at_last_layout_|, and | 142 // the results in |calculated_size_|, |width_at_last_layout_|, and |
| 136 // |width_at_last_size_calculation_|. Returns the needed size. | 143 // |width_at_last_size_calculation_|. Returns the needed size. |
| 137 gfx::Size CalculateAndDoLayout(int width, bool dry_run); | 144 gfx::Size CalculateAndDoLayout(int width, bool dry_run); |
| 138 | 145 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 152 // The listener that will be informed of link clicks. | 159 // The listener that will be informed of link clicks. |
| 153 StyledLabelListener* listener_; | 160 StyledLabelListener* listener_; |
| 154 | 161 |
| 155 // The ranges that should be linkified, sorted by start position. | 162 // The ranges that should be linkified, sorted by start position. |
| 156 StyleRanges style_ranges_; | 163 StyleRanges style_ranges_; |
| 157 | 164 |
| 158 // A mapping from a view to the range it corresponds to in |text_|. Only views | 165 // A mapping from a view to the range it corresponds to in |text_|. Only views |
| 159 // that correspond to ranges with is_link style set will be added to the map. | 166 // that correspond to ranges with is_link style set will be added to the map. |
| 160 std::map<View*, gfx::Range> link_targets_; | 167 std::map<View*, gfx::Range> link_targets_; |
| 161 | 168 |
| 169 // List of views embedded within the label. These views have owned_by_client |
| 170 // set so get deleted by the scoped_ptr destructor (not the views hierarchy). |
| 171 std::vector<scoped_ptr<View>> embedded_views_; |
| 172 |
| 162 // This variable saves the result of the last GetHeightForWidth call in order | 173 // This variable saves the result of the last GetHeightForWidth call in order |
| 163 // to avoid repeated calculation. | 174 // to avoid repeated calculation. |
| 164 mutable gfx::Size calculated_size_; | 175 mutable gfx::Size calculated_size_; |
| 165 mutable int width_at_last_size_calculation_; | 176 mutable int width_at_last_size_calculation_; |
| 166 int width_at_last_layout_; | 177 int width_at_last_layout_; |
| 167 | 178 |
| 168 // Background color on which the label is drawn, for auto color readability. | 179 // Background color on which the label is drawn, for auto color readability. |
| 169 SkColor displayed_on_background_color_; | 180 SkColor displayed_on_background_color_; |
| 170 bool displayed_on_background_color_set_; | 181 bool displayed_on_background_color_set_; |
| 171 | 182 |
| 172 // Controls whether the text is automatically re-colored to be readable on the | 183 // Controls whether the text is automatically re-colored to be readable on the |
| 173 // background. | 184 // background. |
| 174 bool auto_color_readability_enabled_; | 185 bool auto_color_readability_enabled_; |
| 175 | 186 |
| 176 DISALLOW_COPY_AND_ASSIGN(StyledLabel); | 187 DISALLOW_COPY_AND_ASSIGN(StyledLabel); |
| 177 }; | 188 }; |
| 178 | 189 |
| 179 } // namespace views | 190 } // namespace views |
| 180 | 191 |
| 181 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_ | 192 #endif // UI_VIEWS_CONTROLS_STYLED_LABEL_H_ |
| OLD | NEW |