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

Side by Side Diff: chrome/browser/views/infobars/infobar_button_border.cc

Issue 2602003: Refactored the translate infobars. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Synced Created 10 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/views/infobars/infobar_button_border.h"
6
7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h"
9 #include "gfx/canvas.h"
10 #include "grit/app_resources.h"
11 #include "views/controls/button/text_button.h"
12
13 // Preferred padding between text and edge
14 static const int kPreferredPaddingHorizontal = 6;
15 static const int kPreferredPaddingVertical = 5;
16
17 // InfoBarButtonBorder, public: ----------------------------------------------
18
19 InfoBarButtonBorder::InfoBarButtonBorder() {
20 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
21
22 normal_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_N);
23 normal_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_N);
24 normal_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_N);
25 normal_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_N);
26 normal_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_N);
27 normal_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_N);
28 normal_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_N);
29 normal_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_N);
30 normal_set_.bottom_right =
31 rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_N);
32
33 hot_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_H);
34 hot_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_H);
35 hot_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_H);
36 hot_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_H);
37 hot_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_H);
38 hot_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_H);
39 hot_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_H);
40 hot_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_H);
41 hot_set_.bottom_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_H);
42
43 pushed_set_.top_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_LEFT_P);
44 pushed_set_.top = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_P);
45 pushed_set_.top_right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_TOP_RIGHT_P);
46 pushed_set_.left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_LEFT_P);
47 pushed_set_.center = rb.GetBitmapNamed(IDR_INFOBARBUTTON_CENTER_P);
48 pushed_set_.right = rb.GetBitmapNamed(IDR_INFOBARBUTTON_RIGHT_P);
49 pushed_set_.bottom_left = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_LEFT_P);
50 pushed_set_.bottom = rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_P);
51 pushed_set_.bottom_right =
52 rb.GetBitmapNamed(IDR_INFOBARBUTTON_BOTTOM_RIGHT_P);
53 }
54
55 InfoBarButtonBorder::~InfoBarButtonBorder() {
56 }
57
58 // InfoBarButtonBorder, Border overrides: ------------------------------------
59
60 void InfoBarButtonBorder::GetInsets(gfx::Insets* insets) const {
61 insets->Set(kPreferredPaddingVertical, kPreferredPaddingHorizontal,
62 kPreferredPaddingVertical, kPreferredPaddingHorizontal);
63 }
64
65 void InfoBarButtonBorder::Paint(const views::View& view,
66 gfx::Canvas* canvas) const {
67 const views::TextButton* mb = static_cast<const views::TextButton*>(&view);
68 int state = mb->state();
69
70 // TextButton takes care of deciding when to call Paint.
71 const MBBImageSet* set = &normal_set_;
72 if (state == views::TextButton::BS_HOT)
73 set = &hot_set_;
74 else if (state == views::TextButton::BS_PUSHED)
75 set = &pushed_set_;
76
77 gfx::Rect bounds = view.bounds();
78
79 // Draw top left image.
80 canvas->DrawBitmapInt(*set->top_left, 0, 0);
81
82 // Stretch top image.
83 canvas->DrawBitmapInt(
84 *set->top,
85 0, 0, set->top->width(), set->top->height(),
86 set->top_left->width(),
87 0,
88 bounds.width() - set->top_right->width() - set->top_left->width(),
89 set->top->height(), false);
90
91 // Draw top right image.
92 canvas->DrawBitmapInt(*set->top_right,
93 bounds.width() - set->top_right->width(), 0);
94
95 // Stretch left image.
96 canvas->DrawBitmapInt(
97 *set->left,
98 0, 0, set->left->width(), set->left->height(),
99 0,
100 set->top_left->height(),
101 set->top_left->width(),
102 bounds.height() - set->top->height() - set->bottom_left->height(), false);
103
104 // Stretch center image.
105 canvas->DrawBitmapInt(
106 *set->center,
107 0, 0, set->center->width(), set->center->height(),
108 set->left->width(),
109 set->top->height(),
110 bounds.width() - set->right->width() - set->left->width(),
111 bounds.height() - set->bottom->height() - set->top->height(), false);
112
113 // Stretch right image.
114 canvas->DrawBitmapInt(
115 *set->right,
116 0, 0, set->right->width(), set->right->height(),
117 bounds.width() - set->right->width(),
118 set->top_right->height(),
119 set->right->width(),
120 bounds.height() - set->bottom_right->height() -
121 set->top_right->height(), false);
122
123 // Draw bottom left image.
124 canvas->DrawBitmapInt(*set->bottom_left,
125 0,
126 bounds.height() - set->bottom_left->height());
127
128 // Stretch bottom image.
129 canvas->DrawBitmapInt(
130 *set->bottom,
131 0, 0, set->bottom->width(), set->bottom->height(),
132 set->bottom_left->width(),
133 bounds.height() - set->bottom->height(),
134 bounds.width() - set->bottom_right->width() -
135 set->bottom_left->width(),
136 set->bottom->height(), false);
137
138 // Draw bottom right image.
139 canvas->DrawBitmapInt(*set->bottom_right,
140 bounds.width() - set->bottom_right->width(),
141 bounds.height() - set->bottom_right->height());
142 }
OLDNEW
« no previous file with comments | « chrome/browser/views/infobars/infobar_button_border.h ('k') | chrome/browser/views/infobars/infobar_text_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698