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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
// Copyright (c) 2010 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/infobars/infobar_button_border.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "gfx/canvas.h"
#include "grit/theme_resources.h"
#include "views/controls/button/text_button.h"
// Preferred padding between text and edge
static const int kPreferredPaddingHorizontal = 6;
static const int kPreferredPaddingVertical = 5;
// InfoBarButtonBorder, public: ----------------------------------------------
InfoBarButtonBorder::InfoBarButtonBorder() {
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
normal_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_N);
normal_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_N);
normal_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_N);
normal_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_N);
normal_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_N);
normal_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_N);
normal_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_N);
normal_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_N);
normal_set_.bottom_right =
rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_N);
hot_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_H);
hot_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_H);
hot_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_H);
hot_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_H);
hot_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_H);
hot_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_H);
hot_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_H);
hot_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_H);
hot_set_.bottom_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_H);
pushed_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_P);
pushed_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_P);
pushed_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_P);
pushed_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_P);
pushed_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_P);
pushed_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_P);
pushed_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_P);
pushed_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_P);
pushed_set_.bottom_right =
rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_P);
}
InfoBarButtonBorder::~InfoBarButtonBorder() {
}
// InfoBarButtonBorder, Border overrides: ------------------------------------
void InfoBarButtonBorder::GetInsets(gfx::Insets* insets) const {
insets->Set(kPreferredPaddingVertical, kPreferredPaddingHorizontal,
kPreferredPaddingVertical, kPreferredPaddingHorizontal);
}
void InfoBarButtonBorder::Paint(const views::View& view,
gfx::Canvas* canvas) const {
const views::TextButton* mb = static_cast<const views::TextButton*>(&view);
int state = mb->state();
// TextButton takes care of deciding when to call Paint.
const MBBImageSet* set = &normal_set_;
if (state == views::TextButton::BS_HOT)
set = &hot_set_;
else if (state == views::TextButton::BS_PUSHED)
set = &pushed_set_;
gfx::Rect bounds = view.bounds();
// Draw top left image.
canvas->DrawBitmapInt(*set->top_left, 0, 0);
// Stretch top image.
canvas->DrawBitmapInt(
*set->top,
0, 0, set->top->width(), set->top->height(),
set->top_left->width(),
0,
bounds.width() - set->top_right->width() - set->top_left->width(),
set->top->height(), false);
// Draw top right image.
canvas->DrawBitmapInt(*set->top_right,
bounds.width() - set->top_right->width(), 0);
// Stretch left image.
canvas->DrawBitmapInt(
*set->left,
0, 0, set->left->width(), set->left->height(),
0,
set->top_left->height(),
set->top_left->width(),
bounds.height() - set->top->height() - set->bottom_left->height(), false);
// Stretch center image.
canvas->DrawBitmapInt(
*set->center,
0, 0, set->center->width(), set->center->height(),
set->left->width(),
set->top->height(),
bounds.width() - set->right->width() - set->left->width(),
bounds.height() - set->bottom->height() - set->top->height(), false);
// Stretch right image.
canvas->DrawBitmapInt(
*set->right,
0, 0, set->right->width(), set->right->height(),
bounds.width() - set->right->width(),
set->top_right->height(),
set->right->width(),
bounds.height() - set->bottom_right->height() -
set->top_right->height(), false);
// Draw bottom left image.
canvas->DrawBitmapInt(*set->bottom_left,
0,
bounds.height() - set->bottom_left->height());
// Stretch bottom image.
canvas->DrawBitmapInt(
*set->bottom,
0, 0, set->bottom->width(), set->bottom->height(),
set->bottom_left->width(),
bounds.height() - set->bottom->height(),
bounds.width() - set->bottom_right->width() -
set->bottom_left->width(),
set->bottom->height(), false);
// Draw bottom right image.
canvas->DrawBitmapInt(*set->bottom_right,
bounds.width() - set->bottom_right->width(),
bounds.height() - set->bottom_right->height());
}
|