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

Side by Side Diff: chrome/browser/ui/cocoa/tabpose_window.mm

Issue 5729001: Mac: Align tabpose titles on pixel boundaries, making them less blurry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 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
« no previous file with comments | « no previous file | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/ui/cocoa/tabpose_window.h" 5 #import "chrome/browser/ui/cocoa/tabpose_window.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/mac_util.h" 10 #include "base/mac_util.h"
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 class Tile { 368 class Tile {
369 public: 369 public:
370 Tile() {} 370 Tile() {}
371 371
372 // Returns the rectangle this thumbnail is at at the beginning of the zoom-in 372 // Returns the rectangle this thumbnail is at at the beginning of the zoom-in
373 // animation. |tile| is the rectangle that's covering the whole tab area when 373 // animation. |tile| is the rectangle that's covering the whole tab area when
374 // the animation starts. 374 // the animation starts.
375 NSRect GetStartRectRelativeTo(const Tile& tile) const; 375 NSRect GetStartRectRelativeTo(const Tile& tile) const;
376 NSRect thumb_rect() const { return thumb_rect_; } 376 NSRect thumb_rect() const { return thumb_rect_; }
377 377
378 NSRect favicon_rect() const { return favicon_rect_; } 378 NSRect favicon_rect() const { return NSIntegralRect(favicon_rect_); }
379 SkBitmap favicon() const; 379 SkBitmap favicon() const;
380 380
381 // This changes |title_rect| and |favicon_rect| such that the favicon is on 381 // This changes |title_rect| and |favicon_rect| such that the favicon is on
382 // the font's baseline and that the minimum distance between thumb rect and 382 // the font's baseline and that the minimum distance between thumb rect and
383 // favicon and title rects doesn't change. 383 // favicon and title rects doesn't change.
384 // The view code 384 // The view code
385 // 1. queries desired font size by calling |title_font_size()| 385 // 1. queries desired font size by calling |title_font_size()|
386 // 2. loads that font 386 // 2. loads that font
387 // 3. calls |set_font_metrics()| which updates the title rect 387 // 3. calls |set_font_metrics()| which updates the title rect
388 // 4. receives the title rect and puts the title on it with the font from 2. 388 // 4. receives the title rect and puts the title on it with the font from 2.
389 void set_font_metrics(CGFloat ascender, CGFloat descender); 389 void set_font_metrics(CGFloat ascender, CGFloat descender);
390 CGFloat title_font_size() const { return title_font_size_; } 390 CGFloat title_font_size() const { return title_font_size_; }
391 391
392 NSRect title_rect() const { return title_rect_; } 392 NSRect title_rect() const { return NSIntegralRect(title_rect_); }
393 393
394 // Returns an unelided title. The view logic is responsible for eliding. 394 // Returns an unelided title. The view logic is responsible for eliding.
395 const string16& title() const { return contents_->GetTitle(); } 395 const string16& title() const { return contents_->GetTitle(); }
396 396
397 TabContents* tab_contents() const { return contents_; } 397 TabContents* tab_contents() const { return contents_; }
398 void set_tab_contents(TabContents* new_contents) { contents_ = new_contents; } 398 void set_tab_contents(TabContents* new_contents) { contents_ = new_contents; }
399 399
400 private: 400 private:
401 friend class TileSet; 401 friend class TileSet;
402 402
(...skipping 21 matching lines...) Expand all
424 424
425 SkBitmap Tile::favicon() const { 425 SkBitmap Tile::favicon() const {
426 if (contents_->is_app()) { 426 if (contents_->is_app()) {
427 SkBitmap* icon = contents_->GetExtensionAppIcon(); 427 SkBitmap* icon = contents_->GetExtensionAppIcon();
428 if (icon) 428 if (icon)
429 return *icon; 429 return *icon;
430 } 430 }
431 return contents_->GetFavIcon(); 431 return contents_->GetFavIcon();
432 } 432 }
433 433
434 // Changes |title_rect| and |favicon_rect| such that the favicon is on the 434 // Changes |title_rect| and |favicon_rect| such that the favicon's and the
viettrungluu 2010/12/09 18:40:52 "the favicon and title's vertical centers are alig
435 // font's baseline and that the minimum distance between thumb rect and 435 // title's vertical center is aligned and that the minimum distance between
436 // favicon and title rects doesn't change. 436 // the thumb rect and favicon and title rects doesn't change.
437 void Tile::set_font_metrics(CGFloat ascender, CGFloat descender) { 437 void Tile::set_font_metrics(CGFloat ascender, CGFloat descender) {
438 // Make the title height big enough to fit the font, and adopt the title
439 // position to keep its distance from the thumb rect.
438 title_rect_.origin.y -= ascender + descender - NSHeight(title_rect_); 440 title_rect_.origin.y -= ascender + descender - NSHeight(title_rect_);
439 title_rect_.size.height = ascender + descender; 441 title_rect_.size.height = ascender + descender;
440 442
441 if (NSHeight(favicon_rect_) < ascender) { 443 // Align vertical center. Both rects are currently aligned on their top edge.
442 // Move favicon down. 444 CGFloat delta_y = NSMidY(title_rect_) - NSMidY(favicon_rect_);
443 favicon_rect_.origin.y = title_rect_.origin.y + descender; 445 if (delta_y > 0) {
446 // Title is higher: Move favicon down to align the centers.
447 favicon_rect_.origin.y += delta_y;
444 } else { 448 } else {
445 // Move title down. 449 // Favicon is higher: Move title down to align the centers.
446 title_rect_.origin.y = favicon_rect_.origin.y - descender; 450 title_rect_.origin.y -= delta_y;
447 } 451 }
448 } 452 }
449 453
450 // A tileset is responsible for owning and laying out all |Tile|s shown in a 454 // A tileset is responsible for owning and laying out all |Tile|s shown in a
451 // tabpose window. 455 // tabpose window.
452 class TileSet { 456 class TileSet {
453 public: 457 public:
454 TileSet() {} 458 TileSet() {}
455 459
456 // Fills in |tiles_|. 460 // Fills in |tiles_|.
(...skipping 970 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 tile.set_tab_contents(contents->tab_contents()); 1431 tile.set_tab_contents(contents->tab_contents());
1428 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index]; 1432 ThumbnailLayer* thumbLayer = [allThumbnailLayers_ objectAtIndex:index];
1429 [thumbLayer setTabContents:contents->tab_contents()]; 1433 [thumbLayer setTabContents:contents->tab_contents()];
1430 } 1434 }
1431 1435
1432 - (void)tabStripModelDeleted { 1436 - (void)tabStripModelDeleted {
1433 [self close]; 1437 [self close];
1434 } 1438 }
1435 1439
1436 @end 1440 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698