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

Side by Side Diff: ui/message_center/cocoa/notification_controller.mm

Issue 256883002: Update notification style: allow 2-line titles if the message is blank. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix rsesek comments. Created 6 years, 7 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 | « no previous file | ui/message_center/cocoa/notification_controller_unittest.mm » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #import "ui/message_center/cocoa/notification_controller.h" 5 #import "ui/message_center/cocoa/notification_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 CGFloat messageBottomGap = roundf(fabs([[message_ font] descender])); 336 CGFloat messageBottomGap = roundf(fabs([[message_ font] descender]));
337 CGFloat messagePadding = 337 CGFloat messagePadding =
338 message_center::kTextTopPadding - titleBottomGap - messageTopGap; 338 message_center::kTextTopPadding - titleBottomGap - messageTopGap;
339 339
340 CGFloat contextMessageTopGap = roundf( 340 CGFloat contextMessageTopGap = roundf(
341 [[contextMessage_ font] ascender] - [[contextMessage_ font] capHeight]); 341 [[contextMessage_ font] ascender] - [[contextMessage_ font] capHeight]);
342 CGFloat contextMessagePadding = 342 CGFloat contextMessagePadding =
343 message_center::kTextTopPadding - messageBottomGap - contextMessageTopGap; 343 message_center::kTextTopPadding - messageBottomGap - contextMessageTopGap;
344 344
345 // Set the title and recalculate the frame. 345 // Set the title and recalculate the frame.
346 int titleLineLimit = notification_->message().empty()
347 ? message_center::kTitleNoMessageLineLimit
348 : message_center::kTitleLineLimit;
346 [title_ setString:base::SysUTF16ToNSString( 349 [title_ setString:base::SysUTF16ToNSString(
347 [self wrapText:notification_->title() 350 [self wrapText:notification_->title()
348 forFont:[title_ font] 351 forFont:[title_ font]
349 maxNumberOfLines:message_center::kTitleLineLimit])]; 352 maxNumberOfLines:titleLineLimit])];
350 [title_ sizeToFit]; 353 [title_ sizeToFit];
351 NSRect titleFrame = [title_ frame]; 354 NSRect titleFrame = [title_ frame];
352 titleFrame.origin.y = NSMaxY(rootFrame) - titlePadding - NSHeight(titleFrame); 355 titleFrame.origin.y = NSMaxY(rootFrame) - titlePadding - NSHeight(titleFrame);
353 356
354 // Set the message and recalculate the frame. 357 // Set the message and recalculate the frame.
355 [message_ setString:base::SysUTF16ToNSString( 358 [message_ setString:base::SysUTF16ToNSString(
356 [self wrapText:notification_->message() 359 [self wrapText:notification_->message()
357 forFont:[message_ font] 360 forFont:[message_ font]
358 maxNumberOfLines:message_center::kMessageExpandedLineLimit])]; 361 maxNumberOfLines:message_center::kMessageExpandedLineLimit])];
359 [message_ sizeToFit]; 362 [message_ sizeToFit];
360 NSRect messageFrame = [message_ frame]; 363 NSRect messageFrame = [message_ frame];
361 364
362 // If there are list items, then the message_ view should not be displayed. 365 // If there are list items, then the message_ view should not be displayed.
363 const std::vector<message_center::NotificationItem>& items = 366 const std::vector<message_center::NotificationItem>& items =
364 notification->items(); 367 notification->items();
365 if (items.size() > 0) { 368 // If there are list items, don't show the main message. Also if the message
369 // is empty, mark it as hidden and set 0 height, so it doesn't take up any
370 // space (size to fit leaves it 15 px tall.
371 if (items.size() > 0 || notification_->message().empty()) {
366 [message_ setHidden:YES]; 372 [message_ setHidden:YES];
367 messageFrame.origin.y = titleFrame.origin.y; 373 messageFrame.origin.y = titleFrame.origin.y;
368 messageFrame.size.height = 0; 374 messageFrame.size.height = 0;
369 } else { 375 } else {
370 [message_ setHidden:NO]; 376 [message_ setHidden:NO];
371 messageFrame.origin.y = 377 messageFrame.origin.y =
372 NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame); 378 NSMinY(titleFrame) - messagePadding - NSHeight(messageFrame);
373 messageFrame.size.height = NSHeight([message_ frame]); 379 messageFrame.size.height = NSHeight([message_ frame]);
374 } 380 }
375 381
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 if (gfx::GetStringWidth(last, font_list) > width) 813 if (gfx::GetStringWidth(last, font_list) > width)
808 last = gfx::ElideText(last, font_list, width, gfx::ELIDE_AT_END); 814 last = gfx::ElideText(last, font_list, width, gfx::ELIDE_AT_END);
809 wrapped.resize(lines - 1); 815 wrapped.resize(lines - 1);
810 wrapped.push_back(last); 816 wrapped.push_back(last);
811 } 817 }
812 818
813 return lines == 1 ? wrapped[0] : JoinString(wrapped, '\n'); 819 return lines == 1 ? wrapped[0] : JoinString(wrapped, '\n');
814 } 820 }
815 821
816 @end 822 @end
OLDNEW
« no previous file with comments | « no previous file | ui/message_center/cocoa/notification_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698