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

Side by Side Diff: chrome/browser/views/frame/aero_glass_non_client_view.cc

Issue 27317: Support DWM switching.... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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) 2006-2008 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/frame/aero_glass_non_client_view.h"
6
7 #include "chrome/browser/views/frame/browser_view.h"
8 #include "chrome/browser/views/tabs/tab_strip.h"
9 #include "chrome/common/resource_bundle.h"
10 #include "chrome/views/client_view.h"
11 #include "chrome/views/window_resources.h"
12 #include "grit/theme_resources.h"
13
14 // An enumeration of bitmap resources used by this window.
15 enum {
16 // Client Edge Border.
17 FRAME_CLIENT_EDGE_TOP_LEFT,
18 FRAME_CLIENT_EDGE_TOP,
19 FRAME_CLIENT_EDGE_TOP_RIGHT,
20 FRAME_CLIENT_EDGE_RIGHT,
21 FRAME_CLIENT_EDGE_BOTTOM_RIGHT,
22 FRAME_CLIENT_EDGE_BOTTOM,
23 FRAME_CLIENT_EDGE_BOTTOM_LEFT,
24 FRAME_CLIENT_EDGE_LEFT,
25
26 FRAME_PART_BITMAP_COUNT // Must be last.
27 };
28
29 class AeroGlassWindowResources {
30 public:
31 AeroGlassWindowResources() {
32 InitClass();
33 }
34 virtual ~AeroGlassWindowResources() { }
35
36 virtual SkBitmap* GetPartBitmap(views::FramePartBitmap part) const {
37 return standard_frame_bitmaps_[part];
38 }
39
40 private:
41 static void InitClass() {
42 static bool initialized = false;
43 if (!initialized) {
44 static const int kFramePartBitmapIds[] = {
45 IDR_CONTENT_TOP_LEFT_CORNER, IDR_CONTENT_TOP_CENTER,
46 IDR_CONTENT_TOP_RIGHT_CORNER, IDR_CONTENT_RIGHT_SIDE,
47 IDR_CONTENT_BOTTOM_RIGHT_CORNER, IDR_CONTENT_BOTTOM_CENTER,
48 IDR_CONTENT_BOTTOM_LEFT_CORNER, IDR_CONTENT_LEFT_SIDE,
49 };
50
51 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
52 for (int i = 0; i < FRAME_PART_BITMAP_COUNT; ++i)
53 standard_frame_bitmaps_[i] = rb.GetBitmapNamed(kFramePartBitmapIds[i]);
54
55 initialized = true;
56 }
57 }
58
59 static SkBitmap* standard_frame_bitmaps_[FRAME_PART_BITMAP_COUNT];
60
61 DISALLOW_EVIL_CONSTRUCTORS(AeroGlassWindowResources);
62 };
63
64 // static
65 SkBitmap* AeroGlassWindowResources::standard_frame_bitmaps_[];
66
67 AeroGlassWindowResources* AeroGlassNonClientView::resources_ = NULL;
68 SkBitmap* AeroGlassNonClientView::distributor_logo_ = NULL;
69
70 namespace {
71 // There are 3 px of client edge drawn inside the outer frame borders.
72 const int kNonClientBorderThickness = 3;
73 // Besides the frame border, there's another 11 px of empty space atop the
74 // window in restored mode, to use to drag the window around.
75 const int kNonClientRestoredExtraThickness = 11;
76 // In the window corners, the resize areas don't actually expand bigger, but the
77 // 16 px at the end of the top and bottom edges triggers diagonal resizing.
78 const int kResizeAreaCornerSize = 16;
79 // The distributor logo is drawn 3 px from the top of the window.
80 static const int kLogoTopSpacing = 3;
81 // In maximized mode, the OTR avatar starts 2 px below the top of the screen, so
82 // that it doesn't extend into the "3D edge" portion of the titlebar.
83 const int kOTRMaximizedTopSpacing = 2;
84 // The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the
85 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
86 // user).
87 const int kOTRBottomSpacing = 2;
88 // There are 2 px on each side of the OTR avatar (between the frame border and
89 // it on the left, and between it and the tabstrip on the right).
90 const int kOTRSideSpacing = 2;
91 // In restored mode, the New Tab button isn't at the same height as the caption
92 // buttons, but the space will look cluttered if it actually slides under them,
93 // so we stop it when the gap between the two is down to 5 px.
94 const int kNewTabCaptionRestoredSpacing = 5;
95 // In maximized mode, where the New Tab button and the caption buttons are at
96 // similar vertical coordinates, we need to reserve a larger, 16 px gap to avoid
97 // looking too cluttered.
98 const int kNewTabCaptionMaximizedSpacing = 16;
99 // When there's a distributor logo, we leave a 7 px gap between it and the
100 // caption buttons.
101 const int kLogoCaptionSpacing = 7;
102 }
103
104 ///////////////////////////////////////////////////////////////////////////////
105 // AeroGlassNonClientView, public:
106
107 AeroGlassNonClientView::AeroGlassNonClientView(AeroGlassFrame* frame,
108 BrowserView* browser_view)
109 : frame_(frame),
110 browser_view_(browser_view) {
111 InitClass();
112 }
113
114 AeroGlassNonClientView::~AeroGlassNonClientView() {
115 }
116
117 gfx::Rect AeroGlassNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) {
118 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ?
119 (otr_avatar_bounds_.right() + kOTRSideSpacing) :
120 NonClientBorderThickness();
121 int tabstrip_width = frame_->GetMinimizeButtonOffset() - tabstrip_x -
122 (frame_->IsMaximized() ?
123 kNewTabCaptionMaximizedSpacing : kNewTabCaptionRestoredSpacing);
124 return gfx::Rect(tabstrip_x, NonClientTopBorderHeight(),
125 std::max(0, tabstrip_width), tabstrip->GetPreferredHeight());
126 }
127
128 ///////////////////////////////////////////////////////////////////////////////
129 // AeroGlassNonClientView, views::NonClientView implementation:
130
131 gfx::Rect AeroGlassNonClientView::CalculateClientAreaBounds(int width,
132 int height) const {
133 if (!browser_view_->IsTabStripVisible())
134 return gfx::Rect(0, 0, this->width(), this->height());
135
136 int top_height = NonClientTopBorderHeight();
137 int border_thickness = NonClientBorderThickness();
138 return gfx::Rect(border_thickness, top_height,
139 std::max(0, width - (2 * border_thickness)),
140 std::max(0, height - top_height - border_thickness));
141 }
142
143 gfx::Size AeroGlassNonClientView::CalculateWindowSizeForClientSize(
144 int width,
145 int height) const {
146 if (!browser_view_->IsTabStripVisible())
147 return gfx::Size(width, height);
148
149 int border_thickness = NonClientBorderThickness();
150 return gfx::Size(width + (2 * border_thickness),
151 height + NonClientTopBorderHeight() + border_thickness);
152 }
153
154 gfx::Point AeroGlassNonClientView::GetSystemMenuPoint() const {
155 gfx::Point system_menu_point;
156 if (browser_view_->IsBrowserTypeNormal()) {
157 // The X coordinate conditional is because in maximized mode the frame edge
158 // and the client edge are both offscreen, whereas in the opaque frame
159 // (where we don't do this trick) maximized windows have no client edge and
160 // only the frame edge is offscreen.
161 system_menu_point.SetPoint(NonClientBorderThickness() -
162 (browser_view_->CanCurrentlyResize() ? kClientEdgeThickness : 0),
163 NonClientTopBorderHeight() + browser_view_->GetTabStripHeight() -
164 (browser_view_->IsFullscreen() ? 0 : kClientEdgeThickness));
165 } else {
166 system_menu_point.SetPoint(0, -kFrameShadowThickness);
167 }
168 ConvertPointToScreen(this, &system_menu_point);
169 return system_menu_point;
170 }
171
172 int AeroGlassNonClientView::NonClientHitTest(const gfx::Point& point) {
173 // If the browser isn't in normal mode, we haven't customized the frame, so
174 // Windows can figure this out. If the point isn't within our bounds, then
175 // it's in the native portion of the frame, so again Windows can figure it
176 // out.
177 if (!browser_view_->IsBrowserTypeNormal() || !bounds().Contains(point))
178 return HTNOWHERE;
179
180 int frame_component = frame_->client_view()->NonClientHitTest(point);
181 if (frame_component != HTNOWHERE)
182 return frame_component;
183
184 int border_thickness = FrameBorderThickness();
185 int window_component = GetHTComponentForFrame(point, border_thickness,
186 NonClientBorderThickness(), border_thickness,
187 kResizeAreaCornerSize - border_thickness,
188 frame_->window_delegate()->CanResize());
189 // Fall back to the caption if no other component matches.
190 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
191 }
192
193 ///////////////////////////////////////////////////////////////////////////////
194 // AeroGlassNonClientView, views::View overrides:
195
196 void AeroGlassNonClientView::Paint(ChromeCanvas* canvas) {
197 if (!browser_view_->IsTabStripVisible())
198 return; // Nothing is visible, so don't bother to paint.
199
200 PaintDistributorLogo(canvas);
201 PaintToolbarBackground(canvas);
202 PaintOTRAvatar(canvas);
203 PaintClientEdge(canvas);
204 }
205
206 void AeroGlassNonClientView::Layout() {
207 LayoutDistributorLogo();
208 LayoutOTRAvatar();
209 LayoutClientView();
210 }
211
212 void AeroGlassNonClientView::ViewHierarchyChanged(bool is_add,
213 views::View* parent,
214 views::View* child) {
215 if (is_add && child == this) {
216 DCHECK(GetWidget());
217 DCHECK(frame_->client_view()->GetParent() != this);
218 AddChildView(frame_->client_view());
219 }
220 }
221
222 ///////////////////////////////////////////////////////////////////////////////
223 // AeroGlassNonClientView, private:
224
225 int AeroGlassNonClientView::FrameBorderThickness() const {
226 return browser_view_->IsFullscreen() ? 0 : GetSystemMetrics(SM_CXSIZEFRAME);
227 }
228
229 int AeroGlassNonClientView::NonClientBorderThickness() const {
230 return browser_view_->IsFullscreen() ? 0 : kNonClientBorderThickness;
231 }
232
233 int AeroGlassNonClientView::NonClientTopBorderHeight() const {
234 return FrameBorderThickness() + (browser_view_->CanCurrentlyResize() ?
235 kNonClientRestoredExtraThickness : 0);
236 }
237
238 void AeroGlassNonClientView::PaintDistributorLogo(ChromeCanvas* canvas) {
239 // The distributor logo is only painted when the frame is not maximized and
240 // when we actually have a logo.
241 if (!frame_->IsMaximized() && distributor_logo_) {
242 // NOTE: We don't mirror the logo placement here because the outer frame
243 // itself isn't mirrored in RTL. This is a bug; if it is fixed, this should
244 // be mirrored as in opaque_non_client_view.cc.
245 canvas->DrawBitmapInt(*distributor_logo_, logo_bounds_.x(),
246 logo_bounds_.y());
247 }
248 }
249
250 void AeroGlassNonClientView::PaintToolbarBackground(ChromeCanvas* canvas) {
251 gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds());
252 gfx::Point toolbar_origin(toolbar_bounds.origin());
253 View::ConvertPointToView(frame_->client_view(), this, &toolbar_origin);
254 toolbar_bounds.set_origin(toolbar_origin);
255
256 SkBitmap* toolbar_left =
257 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT);
258 canvas->DrawBitmapInt(*toolbar_left,
259 toolbar_bounds.x() - toolbar_left->width(),
260 toolbar_bounds.y());
261
262 SkBitmap* toolbar_center =
263 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP);
264 canvas->TileImageInt(*toolbar_center, toolbar_bounds.x(), toolbar_bounds.y(),
265 toolbar_bounds.width(), toolbar_center->height());
266
267 canvas->DrawBitmapInt(*resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_RIGHT),
268 toolbar_bounds.right(), toolbar_bounds.y());
269 }
270
271 void AeroGlassNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) {
272 if (!browser_view_->ShouldShowOffTheRecordAvatar())
273 return;
274
275 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
276 canvas->DrawBitmapInt(otr_avatar_icon, 0,
277 (otr_avatar_icon.height() - otr_avatar_bounds_.height()) / 2,
278 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(),
279 MirroredLeftPointForRect(otr_avatar_bounds_), otr_avatar_bounds_.y(),
280 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), false);
281 }
282
283 void AeroGlassNonClientView::PaintClientEdge(ChromeCanvas* canvas) {
284 // The client edges start below the toolbar upper corner images regardless
285 // of how tall the toolbar itself is.
286 int client_area_top =
287 frame_->client_view()->y() + browser_view_->GetToolbarBounds().y() +
288 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT)->height();
289
290 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
291 int client_area_bottom =
292 std::max(client_area_top, height() - NonClientBorderThickness());
293 int client_area_height = client_area_bottom - client_area_top;
294 SkBitmap* right = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_RIGHT);
295 canvas->TileImageInt(*right, client_area_bounds.right(), client_area_top,
296 right->width(), client_area_height);
297
298 canvas->DrawBitmapInt(
299 *resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_RIGHT),
300 client_area_bounds.right(), client_area_bottom);
301
302 SkBitmap* bottom = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM);
303 canvas->TileImageInt(*bottom, client_area_bounds.x(),
304 client_area_bottom, client_area_bounds.width(),
305 bottom->height());
306
307 SkBitmap* bottom_left =
308 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_LEFT);
309 canvas->DrawBitmapInt(*bottom_left,
310 client_area_bounds.x() - bottom_left->width(), client_area_bottom);
311
312 SkBitmap* left = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_LEFT);
313 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
314 client_area_top, left->width(), client_area_height);
315 }
316
317 void AeroGlassNonClientView::LayoutDistributorLogo() {
318 if (distributor_logo_) {
319 logo_bounds_.SetRect(frame_->GetMinimizeButtonOffset() -
320 distributor_logo_->width() - kLogoCaptionSpacing, kLogoTopSpacing,
321 distributor_logo_->width(), distributor_logo_->height());
322 } else {
323 logo_bounds_.SetRect(frame_->GetMinimizeButtonOffset(), kLogoTopSpacing, 0,
324 0);
325 }
326 }
327
328 void AeroGlassNonClientView::LayoutOTRAvatar() {
329 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
330 int top_height = NonClientTopBorderHeight();
331 int tabstrip_height, otr_height;
332 if (browser_view_->IsTabStripVisible()) {
333 tabstrip_height = browser_view_->GetTabStripHeight() - kOTRBottomSpacing;
334 otr_height = frame_->IsMaximized() ?
335 (tabstrip_height - kOTRMaximizedTopSpacing) :
336 otr_avatar_icon.height();
337 } else {
338 tabstrip_height = otr_height = 0;
339 }
340 otr_avatar_bounds_.SetRect(NonClientBorderThickness() + kOTRSideSpacing,
341 top_height + tabstrip_height - otr_height,
342 otr_avatar_icon.width(), otr_height);
343 }
344
345 void AeroGlassNonClientView::LayoutClientView() {
346 frame_->client_view()->SetBounds(CalculateClientAreaBounds(width(),
347 height()));
348 }
349
350 // static
351 void AeroGlassNonClientView::InitClass() {
352 static bool initialized = false;
353 if (!initialized) {
354 resources_ = new AeroGlassWindowResources;
355
356 #if defined(GOOGLE_CHROME_BUILD)
357 distributor_logo_ = ResourceBundle::GetSharedInstance().
358 GetBitmapNamed(IDR_DISTRIBUTOR_LOGO);
359 #endif
360
361 initialized = true;
362 }
363 }
364
OLDNEW
« no previous file with comments | « chrome/browser/views/frame/aero_glass_non_client_view.h ('k') | chrome/browser/views/frame/browser_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698