1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/views/tabs/tab_overview_cell.h"
#include "app/gfx/favicon_size.h"
#include "app/gfx/skbitmap_operations.h"
#include "base/string_util.h"
#include "views/border.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/grid_layout.h"
using views::ColumnSet;
using views::GridLayout;
// Padding between the favicon and label.
static const int kFavIconPadding = 4;
// Height of the thumbnail.
static const int kThumbnailHeight = 140;
static const int kThumbnailWidth = 220;
// Padding between favicon/title and thumbnail.
static const int kVerticalPadding = 10;
TabOverviewCell::TabOverviewCell() : configured_thumbnail_(false) {
title_label_ = new views::Label();
title_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
thumbnail_view_ = new views::ImageView();
thumbnail_view_->SetImageSize(gfx::Size(kThumbnailWidth, kThumbnailHeight));
fav_icon_view_ = new views::ImageView();
fav_icon_view_->SetImageSize(gfx::Size(kFavIconSize, kFavIconSize));
int title_cs_id = 0;
int thumbnail_cs_id = 1;
GridLayout* layout = new GridLayout(this);
SetLayoutManager(layout);
ColumnSet* columns = layout->AddColumnSet(title_cs_id);
columns->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
GridLayout::USE_PREF, 0, 0);
columns->AddPaddingColumn(0, kFavIconPadding);
columns->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
GridLayout::USE_PREF, 0, 0);
columns = layout->AddColumnSet(thumbnail_cs_id);
columns->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
layout->StartRow(0, title_cs_id);
layout->AddView(fav_icon_view_);
layout->AddView(title_label_);
layout->StartRowWithPadding(1, thumbnail_cs_id, 0, kVerticalPadding);
layout->AddView(thumbnail_view_);
thumbnail_view_->set_background(
views::Background::CreateSolidBackground(SK_ColorWHITE));
thumbnail_view_->set_border(
views::Border::CreateSolidBorder(1, SkColorSetRGB(176, 176, 176)));
}
void TabOverviewCell::SetThumbnail(const SkBitmap& thumbnail) {
// Do mipmapped-based resampling to get closer to the correct size. The
// input bitmap isn't guaranteed to have any specific resolution.
thumbnail_view_->SetImage(SkBitmapOperations::DownsampleByTwoUntilSize(
thumbnail, kThumbnailWidth, kThumbnailHeight));
configured_thumbnail_ = true;
}
void TabOverviewCell::SetTitle(const string16& title) {
title_label_->SetText(UTF16ToWide(title));
}
void TabOverviewCell::SetFavIcon(const SkBitmap& favicon) {
fav_icon_view_->SetImage(favicon);
}
bool TabOverviewCell::IsPointInThumbnail(const gfx::Point& point) {
return thumbnail_view_->bounds().Contains(point);
}
gfx::Size TabOverviewCell::GetPreferredSize() {
if (!preferred_size_.IsEmpty())
return preferred_size_;
// Force the preferred width to that of the thumbnail.
gfx::Size thumbnail_pref = thumbnail_view_->GetPreferredSize();
gfx::Size pref = View::GetPreferredSize();
pref.set_width(thumbnail_pref.width());
return pref;
}
|