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

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

Issue 20011: Improved OTR avatar and popup window rendering. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/views/frame/aero_glass_non_client_view.h" 5 #include "chrome/browser/views/frame/aero_glass_non_client_view.h"
6 6
7 #include "chrome/app/theme/theme_resources.h" 7 #include "chrome/app/theme/theme_resources.h"
8 #include "chrome/browser/views/frame/browser_view.h" 8 #include "chrome/browser/views/frame/browser_view.h"
9 #include "chrome/browser/views/tabs/tab_strip.h" 9 #include "chrome/browser/views/tabs/tab_strip.h"
10 #include "chrome/common/gfx/chrome_canvas.h" 10 #include "chrome/common/gfx/chrome_canvas.h"
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 static const int kTabStripY = 19; 106 static const int kTabStripY = 19;
107 // How much space on the right is not used for the tab strip (to provide 107 // How much space on the right is not used for the tab strip (to provide
108 // separation between the tabs and the window controls). 108 // separation between the tabs and the window controls).
109 static const int kTabStripRightHorizOffset = 30; 109 static const int kTabStripRightHorizOffset = 30;
110 // A single pixel. 110 // A single pixel.
111 static const int kPixel = 1; 111 static const int kPixel = 1;
112 // The height of the sizing border. 112 // The height of the sizing border.
113 static const int kWindowSizingBorderSize = 8; 113 static const int kWindowSizingBorderSize = 8;
114 // The size (width/height) of the window icon. 114 // The size (width/height) of the window icon.
115 static const int kWindowIconSize = 16; 115 static const int kWindowIconSize = 16;
116 // The distance from the left of the window of the OTR avatar icon. 116 // In maximized mode, the OTR avatar starts 2 px below the top of the screen, so
117 static const int kOTRAvatarIconMargin = 9; 117 // that it doesn't extend into the "3D edge" portion of the titlebar.
118 // The distance from the right edge of the OTR avatar icon to the left edge of 118 const int kOTRMaximizedTopSpacing = 2;
119 // the TabStrip. 119 // The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the
120 static const int kOTRAvatarIconTabStripSpacing = 6; 120 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
121 // The distance from the top of the window of the OTR avatar icon when the 121 // user).
122 // window is maximized. 122 const int kOTRBottomSpacing = 2;
123 static const int kNoTitleOTRTopSpacing = 23; 123 // There are 2 px on each side of the OTR avatar (between the frame border and
124 // The distance from the top of the window of the OTR avatar icon when the 124 // it on the left, and between it and the tabstrip on the right).
125 // window is maximized. 125 const int kOTRSideSpacing = 2;
126 static const int kNoTitleOTRZoomedTopSpacing = 3;
127 126
128 /////////////////////////////////////////////////////////////////////////////// 127 ///////////////////////////////////////////////////////////////////////////////
129 // AeroGlassNonClientView, public: 128 // AeroGlassNonClientView, public:
130 129
131 AeroGlassNonClientView::AeroGlassNonClientView(AeroGlassFrame* frame, 130 AeroGlassNonClientView::AeroGlassNonClientView(AeroGlassFrame* frame,
132 BrowserView* browser_view) 131 BrowserView* browser_view)
133 : frame_(frame), 132 : frame_(frame),
134 browser_view_(browser_view) { 133 browser_view_(browser_view) {
135 InitClass(); 134 InitClass();
136 } 135 }
137 136
138 AeroGlassNonClientView::~AeroGlassNonClientView() { 137 AeroGlassNonClientView::~AeroGlassNonClientView() {
139 } 138 }
140 139
141 gfx::Rect AeroGlassNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) { 140 gfx::Rect AeroGlassNonClientView::GetBoundsForTabStrip(TabStrip* tabstrip) {
142 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ? 141 int tabstrip_x = browser_view_->ShouldShowOffTheRecordAvatar() ?
143 (otr_avatar_bounds_.right() + kOTRAvatarIconTabStripSpacing) : 142 (otr_avatar_bounds_.right() + kOTRSideSpacing) :
144 kWindowHorizontalClientEdgeWidth; 143 kWindowHorizontalClientEdgeWidth;
145 int tabstrip_width = width() - tabstrip_x - kTabStripRightHorizOffset - 144 int tabstrip_width = width() - tabstrip_x - kTabStripRightHorizOffset -
146 (frame_->IsMaximized() ? frame_->GetMinimizeButtonOffset() : 0); 145 (frame_->IsMaximized() ? frame_->GetMinimizeButtonOffset() : 0);
147 int tabstrip_y = 146 int tabstrip_y =
148 frame_->IsMaximized() ? (CalculateNonClientTopHeight() - 2) : kTabStripY; 147 frame_->IsMaximized() ? (CalculateNonClientTopHeight() - 2) : kTabStripY;
149 return gfx::Rect(tabstrip_x, tabstrip_y, std::max(0, tabstrip_width), 148 return gfx::Rect(tabstrip_x, tabstrip_y, std::max(0, tabstrip_width),
150 tabstrip->GetPreferredHeight()); 149 tabstrip->GetPreferredHeight());
151 } 150 }
152 151
153 /////////////////////////////////////////////////////////////////////////////// 152 ///////////////////////////////////////////////////////////////////////////////
154 // AeroGlassNonClientView, views::NonClientView implementation: 153 // AeroGlassNonClientView, views::NonClientView implementation:
155 154
156 gfx::Rect AeroGlassNonClientView::CalculateClientAreaBounds(int win_width, 155 gfx::Rect AeroGlassNonClientView::CalculateClientAreaBounds(int win_width,
157 int win_height) cons t { 156 int win_height) cons t {
158 if (!browser_view_->IsToolbarVisible()) { 157 if (!browser_view_->IsTabStripVisible())
159 // App windows don't have a toolbar.
160 return gfx::Rect(0, 0, width(), height()); 158 return gfx::Rect(0, 0, width(), height());
161 }
162 159
163 int top_margin = CalculateNonClientTopHeight(); 160 int top_margin = CalculateNonClientTopHeight();
164 return gfx::Rect(kWindowHorizontalClientEdgeWidth, top_margin, 161 return gfx::Rect(kWindowHorizontalClientEdgeWidth, top_margin,
165 std::max(0, win_width - (2 * kWindowHorizontalClientEdgeWidth)), 162 std::max(0, win_width - (2 * kWindowHorizontalClientEdgeWidth)),
166 std::max(0, win_height - top_margin - kWindowBottomClientEdgeHeight)); 163 std::max(0, win_height - top_margin - kWindowBottomClientEdgeHeight));
167 } 164 }
168 165
169 gfx::Size AeroGlassNonClientView::CalculateWindowSizeForClientSize( 166 gfx::Size AeroGlassNonClientView::CalculateWindowSizeForClientSize(
170 int width, 167 int width,
171 int height) const { 168 int height) const {
(...skipping 11 matching lines...) Expand all
183 int AeroGlassNonClientView::NonClientHitTest(const gfx::Point& point) { 180 int AeroGlassNonClientView::NonClientHitTest(const gfx::Point& point) {
184 CRect bounds; 181 CRect bounds;
185 CPoint test_point = point.ToPOINT(); 182 CPoint test_point = point.ToPOINT();
186 183
187 // See if the client view intersects the non-client area (e.g. blank areas 184 // See if the client view intersects the non-client area (e.g. blank areas
188 // of the TabStrip). 185 // of the TabStrip).
189 int component = frame_->client_view()->NonClientHitTest(point); 186 int component = frame_->client_view()->NonClientHitTest(point);
190 if (component != HTNOWHERE) 187 if (component != HTNOWHERE)
191 return component; 188 return component;
192 189
193 // This check is only done when we have a toolbar, which is the only time 190 // This check is only done when we have a tabstrip, which is the only time
194 // that we have a non-standard non-client area. 191 // that we have a non-standard non-client area.
195 if (browser_view_->IsToolbarVisible()) { 192 if (browser_view_->IsTabStripVisible()) {
196 // Because we tell Windows that our client area extends all the way to the 193 // Because we tell Windows that our client area extends all the way to the
197 // top of the browser window, but our BrowserView doesn't actually go up tha t 194 // top of the browser window, but our BrowserView doesn't actually go up tha t
198 // high, we need to make sure the right hit-test codes are returned for the 195 // high, we need to make sure the right hit-test codes are returned for the
199 // caption area above the tabs and the top sizing border. 196 // caption area above the tabs and the top sizing border.
200 int client_view_right = 197 int client_view_right =
201 frame_->client_view()->x() + frame_->client_view()->width(); 198 frame_->client_view()->x() + frame_->client_view()->width();
202 if (point.x() >= frame_->client_view()->x() && 199 if (point.x() >= frame_->client_view()->x() &&
203 point.x() < client_view_right) { 200 point.x() < client_view_right) {
204 if (point.y() < kWindowSizingBorderSize) 201 if (point.y() < kWindowSizingBorderSize)
205 return HTTOP; 202 return HTTOP;
(...skipping 16 matching lines...) Expand all
222 } 219 }
223 220
224 void AeroGlassNonClientView::ResetWindowControls() { 221 void AeroGlassNonClientView::ResetWindowControls() {
225 // Our window controls are rendered by the system and do not require reset. 222 // Our window controls are rendered by the system and do not require reset.
226 } 223 }
227 224
228 /////////////////////////////////////////////////////////////////////////////// 225 ///////////////////////////////////////////////////////////////////////////////
229 // AeroGlassNonClientView, views::View overrides: 226 // AeroGlassNonClientView, views::View overrides:
230 227
231 void AeroGlassNonClientView::Paint(ChromeCanvas* canvas) { 228 void AeroGlassNonClientView::Paint(ChromeCanvas* canvas) {
229 PaintDistributorLogo(canvas);
230 if (browser_view_->IsTabStripVisible())
231 PaintToolbarBackground(canvas);
232 PaintOTRAvatar(canvas); 232 PaintOTRAvatar(canvas);
233 PaintDistributorLogo(canvas); 233 if (browser_view_->IsTabStripVisible())
234 if (browser_view_->IsToolbarVisible()) {
235 PaintToolbarBackground(canvas);
236 PaintClientEdge(canvas); 234 PaintClientEdge(canvas);
237 }
238 } 235 }
239 236
240 void AeroGlassNonClientView::Layout() { 237 void AeroGlassNonClientView::Layout() {
241 LayoutOTRAvatar(); 238 LayoutOTRAvatar();
242 LayoutDistributorLogo(); 239 LayoutDistributorLogo();
243 LayoutClientView(); 240 LayoutClientView();
244 } 241 }
245 242
246 gfx::Size AeroGlassNonClientView::GetPreferredSize() { 243 gfx::Size AeroGlassNonClientView::GetPreferredSize() {
247 gfx::Size prefsize = frame_->client_view()->GetPreferredSize(); 244 gfx::Size prefsize = frame_->client_view()->GetPreferredSize();
(...skipping 16 matching lines...) Expand all
264 /////////////////////////////////////////////////////////////////////////////// 261 ///////////////////////////////////////////////////////////////////////////////
265 // AeroGlassNonClientView, private: 262 // AeroGlassNonClientView, private:
266 263
267 int AeroGlassNonClientView::CalculateNonClientTopHeight() const { 264 int AeroGlassNonClientView::CalculateNonClientTopHeight() const {
268 if (frame_->window_delegate()->ShouldShowWindowTitle()) 265 if (frame_->window_delegate()->ShouldShowWindowTitle())
269 return browser_view_->IsToolbarVisible() ? -1 : 0; 266 return browser_view_->IsToolbarVisible() ? -1 : 0;
270 return kNoTitleTopSpacing; 267 return kNoTitleTopSpacing;
271 } 268 }
272 269
273 void AeroGlassNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) { 270 void AeroGlassNonClientView::PaintOTRAvatar(ChromeCanvas* canvas) {
274 if (browser_view_->ShouldShowOffTheRecordAvatar()) { 271 if (!browser_view_->ShouldShowOffTheRecordAvatar())
275 int icon_x = MirroredLeftPointForRect(otr_avatar_bounds_); 272 return;
276 canvas->DrawBitmapInt(browser_view_->GetOTRAvatarIcon(), icon_x, 273
277 otr_avatar_bounds_.y()); 274 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
278 } 275 canvas->DrawBitmapInt(otr_avatar_icon, 0,
276 (otr_avatar_icon.height() - otr_avatar_bounds_.height()) / 2,
277 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(),
278 MirroredLeftPointForRect(otr_avatar_bounds_), otr_avatar_bounds_.y(),
279 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), false);
279 } 280 }
280 281
281 void AeroGlassNonClientView::PaintDistributorLogo(ChromeCanvas* canvas) { 282 void AeroGlassNonClientView::PaintDistributorLogo(ChromeCanvas* canvas) {
282 // The distributor logo is only painted when the frame is not maximized and 283 // The distributor logo is only painted when the frame is not maximized and
283 // when we actually have a logo. 284 // when we actually have a logo.
284 if (!frame_->IsMaximized() && !frame_->IsMinimized() && 285 if (!frame_->IsMaximized() && !frame_->IsMinimized() &&
285 !distributor_logo_.empty()) { 286 !distributor_logo_.empty()) {
286 canvas->DrawBitmapInt(distributor_logo_, logo_bounds_.x(), 287 canvas->DrawBitmapInt(distributor_logo_, logo_bounds_.x(),
287 logo_bounds_.y()); 288 logo_bounds_.y());
288 } 289 }
289 } 290 }
290 291
291 void AeroGlassNonClientView::PaintToolbarBackground(ChromeCanvas* canvas) { 292 void AeroGlassNonClientView::PaintToolbarBackground(ChromeCanvas* canvas) {
292 if (browser_view_->IsToolbarVisible() || 293 SkBitmap* toolbar_left =
293 browser_view_->IsTabStripVisible()) { 294 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT);
294 SkBitmap* toolbar_left = 295 SkBitmap* toolbar_center =
295 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT); 296 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP);
296 SkBitmap* toolbar_center = 297 SkBitmap* toolbar_right =
297 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP); 298 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_RIGHT);
298 SkBitmap* toolbar_right =
299 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_RIGHT);
300 299
301 gfx::Rect toolbar_bounds = browser_view_->GetToolbarBounds(); 300 gfx::Rect toolbar_bounds = browser_view_->GetToolbarBounds();
302 gfx::Point topleft(toolbar_bounds.x(), toolbar_bounds.y()); 301 gfx::Point topleft(toolbar_bounds.x(), toolbar_bounds.y());
303 View::ConvertPointToView(frame_->client_view(), this, &topleft); 302 View::ConvertPointToView(frame_->client_view(), this, &topleft);
304 toolbar_bounds.set_x(topleft.x()); 303 toolbar_bounds.set_x(topleft.x());
305 toolbar_bounds.set_y(topleft.y()); 304 toolbar_bounds.set_y(topleft.y());
306 305
307 // We use TileImageInt for the left and right caps to clip the rendering 306 // We use TileImageInt for the left and right caps to clip the rendering
308 // to the appropriate height of the toolbar. 307 // to the appropriate height of the toolbar.
309 canvas->TileImageInt(*toolbar_left, 308 canvas->TileImageInt(*toolbar_left,
310 toolbar_bounds.x() - toolbar_left->width(), 309 toolbar_bounds.x() - toolbar_left->width(),
311 toolbar_bounds.y(), toolbar_left->width(), 310 toolbar_bounds.y(), toolbar_left->width(),
312 toolbar_bounds.height()); 311 toolbar_bounds.height());
313 canvas->TileImageInt(*toolbar_center, 312 canvas->TileImageInt(*toolbar_center,
314 toolbar_bounds.x(), toolbar_bounds.y(), 313 toolbar_bounds.x(), toolbar_bounds.y(),
315 toolbar_bounds.width(), toolbar_center->height()); 314 toolbar_bounds.width(), toolbar_center->height());
316 canvas->TileImageInt(*toolbar_right, toolbar_bounds.right(), 315 canvas->TileImageInt(*toolbar_right, toolbar_bounds.right(),
317 toolbar_bounds.y(), toolbar_right->width(), 316 toolbar_bounds.y(), toolbar_right->width(),
318 toolbar_bounds.height()); 317 toolbar_bounds.height());
319
320 if (frame_->window_delegate()->ShouldShowWindowTitle()) {
321 // Since we're showing the toolbar or the tabstrip, we need to draw a
322 // single pixel grey line along underneath them to terminate them
323 // cleanly.
324 canvas->FillRectInt(SkColorSetRGB(180, 188, 199), toolbar_bounds.x(),
325 toolbar_bounds.bottom() - 1, toolbar_bounds.width(),
326 1);
327 }
328 }
329 } 318 }
330 319
331 void AeroGlassNonClientView::PaintClientEdge(ChromeCanvas* canvas) { 320 void AeroGlassNonClientView::PaintClientEdge(ChromeCanvas* canvas) {
332 SkBitmap* right = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_RIGHT); 321 SkBitmap* right = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_RIGHT);
333 SkBitmap* bottom_right = 322 SkBitmap* bottom_right =
334 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_RIGHT); 323 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_RIGHT);
335 SkBitmap* bottom = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM); 324 SkBitmap* bottom = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM);
336 SkBitmap* bottom_left = 325 SkBitmap* bottom_left =
337 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_LEFT); 326 resources_->GetPartBitmap(FRAME_CLIENT_EDGE_BOTTOM_LEFT);
338 SkBitmap* left = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_LEFT); 327 SkBitmap* left = resources_->GetPartBitmap(FRAME_CLIENT_EDGE_LEFT);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 client_area_bounds.x() - bottom_left->width(), 359 client_area_bounds.x() - bottom_left->width(),
371 client_area_bounds.bottom() - bottom_left->height() + 360 client_area_bounds.bottom() - bottom_left->height() +
372 kPixel); 361 kPixel);
373 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), 362 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
374 client_area_bounds.y() + fudge, left->width(), 363 client_area_bounds.y() + fudge, left->width(),
375 client_area_bounds.height() - bottom_left->height() + 364 client_area_bounds.height() - bottom_left->height() +
376 kPixel - fudge); 365 kPixel - fudge);
377 } 366 }
378 367
379 void AeroGlassNonClientView::LayoutOTRAvatar() { 368 void AeroGlassNonClientView::LayoutOTRAvatar() {
380 int otr_x = 0; 369 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
381 int top_spacing = frame_->IsMaximized() ? kNoTitleOTRZoomedTopSpacing 370 int top_height = (frame_->IsMaximized() ?
382 : kNoTitleOTRTopSpacing; 371 (CalculateNonClientTopHeight() - 2) : kTabStripY);
383 int otr_y = browser_view_->GetTabStripHeight() + top_spacing; 372 int tabstrip_height = browser_view_->GetTabStripHeight() - kOTRBottomSpacing;
384 int otr_width = 0; 373 int otr_height = frame_->IsMaximized() ?
385 int otr_height = 0; 374 (tabstrip_height - kOTRMaximizedTopSpacing) :
386 if (browser_view_->ShouldShowOffTheRecordAvatar()) { 375 otr_avatar_icon.height();
387 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 376 otr_avatar_bounds_.SetRect(
388 otr_width = otr_avatar_icon.width(); 377 kWindowHorizontalClientEdgeWidth + kOTRSideSpacing,
389 otr_height = otr_avatar_icon.height(); 378 top_height + tabstrip_height - otr_height, otr_avatar_icon.width(),
390 otr_x = kOTRAvatarIconMargin; 379 otr_height);
391 otr_y -= otr_avatar_icon.height() + 2;
392 }
393 otr_avatar_bounds_.SetRect(otr_x, otr_y, otr_width, otr_height);
394 } 380 }
395 381
396 void AeroGlassNonClientView::LayoutDistributorLogo() { 382 void AeroGlassNonClientView::LayoutDistributorLogo() {
397 if (distributor_logo_.empty()) 383 if (distributor_logo_.empty())
398 return; 384 return;
399 385
400 int logo_w = distributor_logo_.width(); 386 int logo_w = distributor_logo_.width();
401 int logo_h = distributor_logo_.height(); 387 int logo_h = distributor_logo_.height();
402 388
403 int w = width(); 389 int w = width();
(...skipping 16 matching lines...) Expand all
420 resources_ = new AeroGlassWindowResources; 406 resources_ = new AeroGlassWindowResources;
421 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 407 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
422 #if defined(GOOGLE_CHROME_BUILD) 408 #if defined(GOOGLE_CHROME_BUILD)
423 distributor_logo_ = *rb.GetBitmapNamed(IDR_DISTRIBUTOR_LOGO); 409 distributor_logo_ = *rb.GetBitmapNamed(IDR_DISTRIBUTOR_LOGO);
424 #endif 410 #endif
425 411
426 initialized = true; 412 initialized = true;
427 } 413 }
428 } 414 }
429 415
OLDNEW
« no previous file with comments | « chrome/browser/views/frame/aero_glass_frame.cc ('k') | chrome/browser/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698