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

Side by Side Diff: ui/views/window/custom_frame_view.cc

Issue 10447053: Converts remainder of ui and chrome/browser/ui/views/frame to use ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/window/custom_frame_view.h ('k') | ui/views/window/frame_background.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/window/custom_frame_view.h" 5 #include "ui/views/window/custom_frame_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "grit/ui_resources.h" 10 #include "grit/ui_resources.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2; 311 unavailable_px_at_top - size - TitlebarBottomThickness() + 1) / 2;
312 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size); 312 return gfx::Rect(frame_thickness + kIconLeftSpacing, y, size, size);
313 } 313 }
314 314
315 bool CustomFrameView::ShouldShowClientEdge() const { 315 bool CustomFrameView::ShouldShowClientEdge() const {
316 return !frame_->IsMaximized(); 316 return !frame_->IsMaximized();
317 } 317 }
318 318
319 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) { 319 void CustomFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) {
320 frame_background_->set_frame_color(GetFrameColor()); 320 frame_background_->set_frame_color(GetFrameColor());
321 const SkBitmap* frame_image = GetFrameBitmap(); 321 const gfx::ImageSkia* frame_image = GetFrameImage();
322 frame_background_->set_theme_bitmap(frame_image); 322 frame_background_->set_theme_image(frame_image);
323 frame_background_->set_top_area_height(frame_image->height()); 323 frame_background_->set_top_area_height(frame_image->height());
324 324
325 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 325 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
326 326
327 frame_background_->SetCornerImages( 327 frame_background_->SetCornerImages(
328 rb.GetImageNamed(IDR_WINDOW_TOP_LEFT_CORNER).ToSkBitmap(), 328 rb.GetImageNamed(IDR_WINDOW_TOP_LEFT_CORNER).ToImageSkia(),
329 rb.GetImageNamed(IDR_WINDOW_TOP_RIGHT_CORNER).ToSkBitmap(), 329 rb.GetImageNamed(IDR_WINDOW_TOP_RIGHT_CORNER).ToImageSkia(),
330 rb.GetImageNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER).ToSkBitmap(), 330 rb.GetImageNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER).ToImageSkia(),
331 rb.GetImageNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER).ToSkBitmap()); 331 rb.GetImageNamed(IDR_WINDOW_BOTTOM_RIGHT_CORNER).ToImageSkia());
332 frame_background_->SetSideImages( 332 frame_background_->SetSideImages(
333 rb.GetImageNamed(IDR_WINDOW_LEFT_SIDE).ToSkBitmap(), 333 rb.GetImageNamed(IDR_WINDOW_LEFT_SIDE).ToImageSkia(),
334 rb.GetImageNamed(IDR_WINDOW_TOP_CENTER).ToSkBitmap(), 334 rb.GetImageNamed(IDR_WINDOW_TOP_CENTER).ToImageSkia(),
335 rb.GetImageNamed(IDR_WINDOW_RIGHT_SIDE).ToSkBitmap(), 335 rb.GetImageNamed(IDR_WINDOW_RIGHT_SIDE).ToImageSkia(),
336 rb.GetImageNamed(IDR_WINDOW_BOTTOM_CENTER).ToSkBitmap()); 336 rb.GetImageNamed(IDR_WINDOW_BOTTOM_CENTER).ToImageSkia());
337 337
338 frame_background_->PaintRestored(canvas, this); 338 frame_background_->PaintRestored(canvas, this);
339 } 339 }
340 340
341 void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { 341 void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) {
342 const SkBitmap* frame_image = GetFrameBitmap(); 342 const gfx::ImageSkia* frame_image = GetFrameImage();
343 frame_background_->set_theme_bitmap(frame_image); 343 frame_background_->set_theme_image(frame_image);
344 frame_background_->set_top_area_height(frame_image->height()); 344 frame_background_->set_top_area_height(frame_image->height());
345 frame_background_->PaintMaximized(canvas, this); 345 frame_background_->PaintMaximized(canvas, this);
346 346
347 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 347 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
348 348
349 // TODO(jamescook): Migrate this into FrameBackground. 349 // TODO(jamescook): Migrate this into FrameBackground.
350 // The bottom of the titlebar actually comes from the top of the Client Edge 350 // The bottom of the titlebar actually comes from the top of the Client Edge
351 // graphic, with the actual client edge clipped off the bottom. 351 // graphic, with the actual client edge clipped off the bottom.
352 const SkBitmap* titlebar_bottom = rb.GetImageNamed( 352 const gfx::ImageSkia* titlebar_bottom = rb.GetImageNamed(
353 IDR_APP_TOP_CENTER).ToSkBitmap(); 353 IDR_APP_TOP_CENTER).ToImageSkia();
354 int edge_height = titlebar_bottom->height() - 354 int edge_height = titlebar_bottom->height() -
355 (ShouldShowClientEdge() ? kClientEdgeThickness : 0); 355 (ShouldShowClientEdge() ? kClientEdgeThickness : 0);
356 canvas->TileImageInt(*titlebar_bottom, 0, 356 canvas->TileImageInt(*titlebar_bottom, 0,
357 frame_->client_view()->y() - edge_height, width(), edge_height); 357 frame_->client_view()->y() - edge_height, width(), edge_height);
358 } 358 }
359 359
360 void CustomFrameView::PaintTitleBar(gfx::Canvas* canvas) { 360 void CustomFrameView::PaintTitleBar(gfx::Canvas* canvas) {
361 WidgetDelegate* delegate = frame_->widget_delegate(); 361 WidgetDelegate* delegate = frame_->widget_delegate();
362 362
363 // It seems like in some conditions we can be asked to paint after the window 363 // It seems like in some conditions we can be asked to paint after the window
364 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The 364 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The
365 // correct long term fix may be to shut down the RootView in WM_DESTROY. 365 // correct long term fix may be to shut down the RootView in WM_DESTROY.
366 if (!delegate) 366 if (!delegate)
367 return; 367 return;
368 368
369 canvas->DrawStringInt(delegate->GetWindowTitle(), GetTitleFont(), 369 canvas->DrawStringInt(delegate->GetWindowTitle(), GetTitleFont(),
370 SK_ColorWHITE, GetMirroredXForRect(title_bounds_), 370 SK_ColorWHITE, GetMirroredXForRect(title_bounds_),
371 title_bounds_.y(), title_bounds_.width(), 371 title_bounds_.y(), title_bounds_.width(),
372 title_bounds_.height()); 372 title_bounds_.height());
373 } 373 }
374 374
375 void CustomFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) { 375 void CustomFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
376 gfx::Rect client_area_bounds = frame_->client_view()->bounds(); 376 gfx::Rect client_area_bounds = frame_->client_view()->bounds();
377 int client_area_top = client_area_bounds.y(); 377 int client_area_top = client_area_bounds.y();
378 378
379 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 379 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
380 const SkBitmap* top_left = rb.GetImageNamed(IDR_APP_TOP_LEFT).ToSkBitmap(); 380 const gfx::ImageSkia* top_left = rb.GetImageNamed(
381 const SkBitmap* top = rb.GetImageNamed(IDR_APP_TOP_CENTER).ToSkBitmap(); 381 IDR_APP_TOP_LEFT).ToImageSkia();
382 const SkBitmap* top_right = rb.GetImageNamed(IDR_APP_TOP_RIGHT).ToSkBitmap(); 382 const gfx::ImageSkia* top = rb.GetImageNamed(
383 const SkBitmap* right = rb.GetImageNamed(IDR_CONTENT_RIGHT_SIDE).ToSkBitmap(); 383 IDR_APP_TOP_CENTER).ToImageSkia();
384 const SkBitmap* bottom_right = rb.GetImageNamed( 384 const gfx::ImageSkia* top_right = rb.GetImageNamed(
385 IDR_CONTENT_BOTTOM_RIGHT_CORNER).ToSkBitmap(); 385 IDR_APP_TOP_RIGHT).ToImageSkia();
386 const SkBitmap* bottom = rb.GetImageNamed( 386 const gfx::ImageSkia* right = rb.GetImageNamed(
387 IDR_CONTENT_BOTTOM_CENTER).ToSkBitmap(); 387 IDR_CONTENT_RIGHT_SIDE).ToImageSkia();
388 const SkBitmap* bottom_left = rb.GetImageNamed( 388 const gfx::ImageSkia* bottom_right = rb.GetImageNamed(
389 IDR_CONTENT_BOTTOM_LEFT_CORNER).ToSkBitmap(); 389 IDR_CONTENT_BOTTOM_RIGHT_CORNER).ToImageSkia();
390 const SkBitmap* left = rb.GetImageNamed(IDR_CONTENT_LEFT_SIDE).ToSkBitmap(); 390 const gfx::ImageSkia* bottom = rb.GetImageNamed(
391 IDR_CONTENT_BOTTOM_CENTER).ToImageSkia();
392 const gfx::ImageSkia* bottom_left = rb.GetImageNamed(
393 IDR_CONTENT_BOTTOM_LEFT_CORNER).ToImageSkia();
394 const gfx::ImageSkia* left = rb.GetImageNamed(
395 IDR_CONTENT_LEFT_SIDE).ToImageSkia();
391 396
392 // Top. 397 // Top.
393 int top_edge_y = client_area_top - top->height(); 398 int top_edge_y = client_area_top - top->height();
394 canvas->DrawBitmapInt(*top_left, client_area_bounds.x() - top_left->width(), 399 canvas->DrawBitmapInt(*top_left, client_area_bounds.x() - top_left->width(),
395 top_edge_y); 400 top_edge_y);
396 canvas->TileImageInt(*top, client_area_bounds.x(), top_edge_y, 401 canvas->TileImageInt(*top, client_area_bounds.x(), top_edge_y,
397 client_area_bounds.width(), top->height()); 402 client_area_bounds.width(), top->height());
398 canvas->DrawBitmapInt(*top_right, client_area_bounds.right(), top_edge_y); 403 canvas->DrawBitmapInt(*top_right, client_area_bounds.right(), top_edge_y);
399 404
400 // Right. 405 // Right.
(...skipping 18 matching lines...) Expand all
419 // Draw the color to fill in the edges. 424 // Draw the color to fill in the edges.
420 canvas->FillRect(gfx::Rect(client_area_bounds.x() - 1, client_area_top - 1, 425 canvas->FillRect(gfx::Rect(client_area_bounds.x() - 1, client_area_top - 1,
421 client_area_bounds.width() + 1, client_area_bottom - client_area_top + 1), 426 client_area_bounds.width() + 1, client_area_bottom - client_area_top + 1),
422 kClientEdgeColor); 427 kClientEdgeColor);
423 } 428 }
424 429
425 SkColor CustomFrameView::GetFrameColor() const { 430 SkColor CustomFrameView::GetFrameColor() const {
426 return frame_->IsActive() ? kDefaultColorFrame : kDefaultColorFrameInactive; 431 return frame_->IsActive() ? kDefaultColorFrame : kDefaultColorFrameInactive;
427 } 432 }
428 433
429 const SkBitmap* CustomFrameView::GetFrameBitmap() const { 434 const gfx::ImageSkia* CustomFrameView::GetFrameImage() const {
430 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 435 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
431 frame_->IsActive() ? IDR_FRAME : IDR_FRAME_INACTIVE).ToSkBitmap(); 436 frame_->IsActive() ? IDR_FRAME : IDR_FRAME_INACTIVE).ToImageSkia();
432 } 437 }
433 438
434 void CustomFrameView::LayoutWindowControls() { 439 void CustomFrameView::LayoutWindowControls() {
435 close_button_->SetImageAlignment(ImageButton::ALIGN_LEFT, 440 close_button_->SetImageAlignment(ImageButton::ALIGN_LEFT,
436 ImageButton::ALIGN_BOTTOM); 441 ImageButton::ALIGN_BOTTOM);
437 int caption_y = CaptionButtonY(); 442 int caption_y = CaptionButtonY();
438 bool is_maximized = frame_->IsMaximized(); 443 bool is_maximized = frame_->IsMaximized();
439 // There should always be the same number of non-shadow pixels visible to the 444 // There should always be the same number of non-shadow pixels visible to the
440 // side of the caption buttons. In maximized mode we extend the rightmost 445 // side of the caption buttons. In maximized mode we extend the rightmost
441 // button to the screen corner to obey Fitts' Law. 446 // button to the screen corner to obey Fitts' Law.
442 int right_extra_width = is_maximized ? 447 int right_extra_width = is_maximized ?
443 (kFrameBorderThickness - kFrameShadowThickness) : 0; 448 (kFrameBorderThickness - kFrameShadowThickness) : 0;
444 gfx::Size close_button_size = close_button_->GetPreferredSize(); 449 gfx::Size close_button_size = close_button_->GetPreferredSize();
445 close_button_->SetBounds(width() - FrameBorderThickness() - 450 close_button_->SetBounds(width() - FrameBorderThickness() -
446 right_extra_width - close_button_size.width(), caption_y, 451 right_extra_width - close_button_size.width(), caption_y,
447 close_button_size.width() + right_extra_width, 452 close_button_size.width() + right_extra_width,
448 close_button_size.height()); 453 close_button_size.height());
449 454
450 // When the window is restored, we show a maximized button; otherwise, we show 455 // When the window is restored, we show a maximized button; otherwise, we show
451 // a restore button. 456 // a restore button.
452 bool is_restored = !is_maximized && !frame_->IsMinimized(); 457 bool is_restored = !is_maximized && !frame_->IsMinimized();
453 ImageButton* invisible_button = is_restored ? restore_button_ 458 ImageButton* invisible_button = is_restored ? restore_button_
454 : maximize_button_; 459 : maximize_button_;
455 invisible_button->SetVisible(false); 460 invisible_button->SetVisible(false);
456 461
457 ImageButton* visible_button = is_restored ? maximize_button_ 462 ImageButton* visible_button = is_restored ? maximize_button_
458 : restore_button_; 463 : restore_button_;
459 FramePartBitmap normal_part, hot_part, pushed_part; 464 FramePartImage normal_part, hot_part, pushed_part;
460 if (should_show_minmax_buttons_) { 465 if (should_show_minmax_buttons_) {
461 visible_button->SetVisible(true); 466 visible_button->SetVisible(true);
462 visible_button->SetImageAlignment(ImageButton::ALIGN_LEFT, 467 visible_button->SetImageAlignment(ImageButton::ALIGN_LEFT,
463 ImageButton::ALIGN_BOTTOM); 468 ImageButton::ALIGN_BOTTOM);
464 gfx::Size visible_button_size = visible_button->GetPreferredSize(); 469 gfx::Size visible_button_size = visible_button->GetPreferredSize();
465 visible_button->SetBounds(close_button_->x() - visible_button_size.width(), 470 visible_button->SetBounds(close_button_->x() - visible_button_size.width(),
466 caption_y, visible_button_size.width(), 471 caption_y, visible_button_size.width(),
467 visible_button_size.height()); 472 visible_button_size.height());
468 473
469 minimize_button_->SetVisible(true); 474 minimize_button_->SetVisible(true);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 rb.GetImageNamed(normal_image_id).ToImageSkia()); 546 rb.GetImageNamed(normal_image_id).ToImageSkia());
542 button->SetImage(CustomButton::BS_HOT, 547 button->SetImage(CustomButton::BS_HOT,
543 rb.GetImageNamed(hot_image_id).ToImageSkia()); 548 rb.GetImageNamed(hot_image_id).ToImageSkia());
544 button->SetImage(CustomButton::BS_PUSHED, 549 button->SetImage(CustomButton::BS_PUSHED,
545 rb.GetImageNamed(pushed_image_id).ToImageSkia()); 550 rb.GetImageNamed(pushed_image_id).ToImageSkia());
546 AddChildView(button); 551 AddChildView(button);
547 return button; 552 return button;
548 } 553 }
549 554
550 } // namespace views 555 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/window/custom_frame_view.h ('k') | ui/views/window/frame_background.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698