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

Side by Side Diff: chrome/browser/ui/views/download/download_item_view.h

Issue 2556573002: Fix SizeLabelToMinWidth() function such that no unnecessary space (Closed)
Patch Set: change to static function Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // A view that implements one download on the Download shelf. 5 // A view that implements one download on the Download shelf.
6 // Each DownloadItemView contains an application icon, a text label 6 // Each DownloadItemView contains an application icon, a text label
7 // indicating the download's file name, a text label indicating the 7 // indicating the download's file name, a text label indicating the
8 // download's status (such as the number of bytes downloaded so far) 8 // download's status (such as the number of bytes downloaded so far)
9 // and a button for canceling an in progress download, or opening 9 // and a button for canceling an in progress download, or opening
10 // the completed download. 10 // the completed download.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // gfx::AnimationDelegate implementation. 129 // gfx::AnimationDelegate implementation.
130 void AnimationProgressed(const gfx::Animation* animation) override; 130 void AnimationProgressed(const gfx::Animation* animation) override;
131 131
132 protected: 132 protected:
133 // Overridden from views::View: 133 // Overridden from views::View:
134 void OnPaint(gfx::Canvas* canvas) override; 134 void OnPaint(gfx::Canvas* canvas) override;
135 void OnFocus() override; 135 void OnFocus() override;
136 void OnBlur() override; 136 void OnBlur() override;
137 137
138 private: 138 private:
139 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest,
140 AdjustTextAndGetSize_VeryShortText);
141 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest,
142 AdjustTextAndGetSize_MoreTextOnFirstLine);
143 FRIEND_TEST_ALL_PREFIXES(DownloadItemViewDangerousDownloadLabelTest,
144 AdjustTextAndGetSize_VeryLongTextWithoutSpace);
Peter Kasting 2016/12/08 21:53:52 Nit: No strong feeling here, but if you had a sing
Jialiu Lin 2016/12/08 22:44:03 merged into a single test case.
145
139 enum State { NORMAL = 0, HOT, PUSHED }; 146 enum State { NORMAL = 0, HOT, PUSHED };
140 class DropDownButton; 147 class DropDownButton;
141 148
142 enum Mode { 149 enum Mode {
143 NORMAL_MODE = 0, // Showing download item. 150 NORMAL_MODE = 0, // Showing download item.
144 DANGEROUS_MODE, // Displaying the dangerous download warning. 151 DANGEROUS_MODE, // Displaying the dangerous download warning.
145 MALICIOUS_MODE // Displaying the malicious download warning. 152 MALICIOUS_MODE // Displaying the malicious download warning.
146 }; 153 };
147 154
148 void OpenDownload(); 155 void OpenDownload();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 bool IsShowingWarningDialog() const { 197 bool IsShowingWarningDialog() const {
191 return mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE; 198 return mode_ == DANGEROUS_MODE || mode_ == MALICIOUS_MODE;
192 } 199 }
193 200
194 // Clears or shows the warning dialog as per the state of |model_|. 201 // Clears or shows the warning dialog as per the state of |model_|.
195 void ToggleWarningDialog(); 202 void ToggleWarningDialog();
196 203
197 // Reverts from dangerous mode to normal download mode. 204 // Reverts from dangerous mode to normal download mode.
198 void ClearWarningDialog(); 205 void ClearWarningDialog();
199 206
200 // Start displaying the dangerous download warning or the malicious download 207 // Starts displaying the dangerous download warning or the malicious download
201 // warning. 208 // warning.
202 void ShowWarningDialog(); 209 void ShowWarningDialog();
203 210
204 // Returns the current warning icon (should only be called when the view is 211 // Returns the current warning icon (should only be called when the view is
205 // actually showing a warning). 212 // actually showing a warning).
206 gfx::ImageSkia GetWarningIcon(); 213 gfx::ImageSkia GetWarningIcon();
207 214
208 // Sets |size| with the size of the Save and Discard buttons (they have the 215 // Sets |size| with the size of the Save and Discard buttons (they have the
209 // same size). 216 // same size).
210 gfx::Size GetButtonSize() const; 217 gfx::Size GetButtonSize() const;
211 218
212 // Sizes the dangerous download label to a minimum width available using 2 219 // Sizes the dangerous download label to a minimum width available using 2
213 // lines. The size is computed only the first time this method is invoked 220 // lines. The size is computed only the first time this method is invoked
214 // and simply returned on subsequent calls. 221 // and simply returned on subsequent calls.
215 void SizeLabelToMinWidth(); 222 void SizeLabelToMinWidth();
216 223
224 // Called by SizeLabelToMinWidth() to compute the optimal size (a.k.a minimum
225 // width) of a label and set its text accordingly.
Peter Kasting 2016/12/08 21:53:52 Nit: Maybe more detail would help, especially for
Jialiu Lin 2016/12/08 22:44:03 Done.
226 static gfx::Size AdjustTextAndGetSize(views::Label* label);
227
217 // Reenables the item after it has been disabled when a user clicked it to 228 // Reenables the item after it has been disabled when a user clicked it to
218 // open the downloaded file. 229 // open the downloaded file.
219 void Reenable(); 230 void Reenable();
220 231
221 // Releases drop down button after showing a context menu. 232 // Releases drop down button after showing a context menu.
222 void ReleaseDropdown(); 233 void ReleaseDropdown();
223 234
224 // Update the accessible name to reflect the current state of the control, 235 // Update the accessible name to reflect the current state of the control,
225 // so that screenreaders can access the filename, status text, and 236 // so that screenreaders can access the filename, status text, and
226 // dangerous download warning message (if any). 237 // dangerous download warning message (if any).
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_; 340 std::unique_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
330 341
331 // Method factory used to delay reenabling of the item when opening the 342 // Method factory used to delay reenabling of the item when opening the
332 // downloaded file. 343 // downloaded file.
333 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_; 344 base::WeakPtrFactory<DownloadItemView> weak_ptr_factory_;
334 345
335 DISALLOW_COPY_AND_ASSIGN(DownloadItemView); 346 DISALLOW_COPY_AND_ASSIGN(DownloadItemView);
336 }; 347 };
337 348
338 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_ 349 #endif // CHROME_BROWSER_UI_VIEWS_DOWNLOAD_DOWNLOAD_ITEM_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698