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

Side by Side Diff: chrome/browser/gtk/tabs/tab_renderer_gtk.cc

Issue 113443: ChromeCanvas->gfx::Canvas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « chrome/browser/gtk/tabs/tab_renderer_gtk.h ('k') | chrome/browser/gtk/tabs/tab_strip_gtk.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gtk/tabs/tab_renderer_gtk.h" 5 #include "chrome/browser/gtk/tabs/tab_renderer_gtk.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "chrome/browser/browser.h" 9 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_theme_provider.h" 10 #include "chrome/browser/browser_theme_provider.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 } 277 }
278 278
279 void TabRendererGtk::AnimationEnded(const Animation* animation) { 279 void TabRendererGtk::AnimationEnded(const Animation* animation) {
280 gtk_widget_queue_draw(tab_.get()); 280 gtk_widget_queue_draw(tab_.get());
281 } 281 }
282 282
283 //////////////////////////////////////////////////////////////////////////////// 283 ////////////////////////////////////////////////////////////////////////////////
284 // TabRendererGtk, private: 284 // TabRendererGtk, private:
285 285
286 void TabRendererGtk::Paint(GdkEventExpose* event) { 286 void TabRendererGtk::Paint(GdkEventExpose* event) {
287 ChromeCanvasPaint canvas(event, false); 287 gfx::CanvasPaint canvas(event, false);
288 if (canvas.isEmpty()) 288 if (canvas.isEmpty())
289 return; 289 return;
290 290
291 // Don't paint if we're narrower than we can render correctly. (This should 291 // Don't paint if we're narrower than we can render correctly. (This should
292 // only happen during animations). 292 // only happen during animations).
293 if (width() < GetMinimumUnselectedSize().width()) 293 if (width() < GetMinimumUnselectedSize().width())
294 return; 294 return;
295 295
296 // See if the model changes whether the icons should be painted. 296 // See if the model changes whether the icons should be painted.
297 const bool show_icon = ShouldShowIcon(); 297 const bool show_icon = ShouldShowIcon();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } else { 399 } else {
400 title_width = std::max(local_bounds.width() - title_left, 0); 400 title_width = std::max(local_bounds.width() - title_left, 0);
401 } 401 }
402 if (data_.show_download_icon) 402 if (data_.show_download_icon)
403 title_width = std::max(title_width - download_icon_width_, 0); 403 title_width = std::max(title_width - download_icon_width_, 0);
404 title_bounds_.SetRect(title_left, title_top, title_width, title_font_height_); 404 title_bounds_.SetRect(title_left, title_top, title_width, title_font_height_);
405 405
406 // TODO(jhawkins): Handle RTL layout. 406 // TODO(jhawkins): Handle RTL layout.
407 } 407 }
408 408
409 void TabRendererGtk::PaintTabBackground(ChromeCanvasPaint* canvas) { 409 void TabRendererGtk::PaintTabBackground(gfx::CanvasPaint* canvas) {
410 if (IsSelected()) { 410 if (IsSelected()) {
411 // Sometimes detaching a tab quickly can result in the model reporting it 411 // Sometimes detaching a tab quickly can result in the model reporting it
412 // as not being selected, so is_drag_clone_ ensures that we always paint 412 // as not being selected, so is_drag_clone_ ensures that we always paint
413 // the active representation for the dragged tab. 413 // the active representation for the dragged tab.
414 PaintActiveTabBackground(canvas); 414 PaintActiveTabBackground(canvas);
415 } else { 415 } else {
416 // Draw our hover state. 416 // Draw our hover state.
417 Animation* animation = hover_animation_.get(); 417 Animation* animation = hover_animation_.get();
418 418
419 PaintInactiveTabBackground(canvas); 419 PaintInactiveTabBackground(canvas);
420 if (animation->GetCurrentValue() > 0) { 420 if (animation->GetCurrentValue() > 0) {
421 SkRect bounds; 421 SkRect bounds;
422 // TODO(jhawkins): This will only work for the first tab, because 422 // TODO(jhawkins): This will only work for the first tab, because
423 // saveLayerAlpha only uses bounds as the size and not the location. In 423 // saveLayerAlpha only uses bounds as the size and not the location. In
424 // our situation, canvas spans the entire tabstrip, so saving the layer 424 // our situation, canvas spans the entire tabstrip, so saving the layer
425 // at (0,0)x(w,h) will always save the first tab. 425 // at (0,0)x(w,h) will always save the first tab.
426 bounds.set(0, 0, 426 bounds.set(0, 0,
427 SkIntToScalar(width()), SkIntToScalar(height())); 427 SkIntToScalar(width()), SkIntToScalar(height()));
428 canvas->saveLayerAlpha(&bounds, 428 canvas->saveLayerAlpha(&bounds,
429 static_cast<int>(animation->GetCurrentValue() * kHoverOpacity * 0xff), 429 static_cast<int>(animation->GetCurrentValue() * kHoverOpacity * 0xff),
430 SkCanvas::kARGB_ClipLayer_SaveFlag); 430 SkCanvas::kARGB_ClipLayer_SaveFlag);
431 canvas->drawARGB(0, 255, 255, 255, SkPorterDuff::kClear_Mode); 431 canvas->drawARGB(0, 255, 255, 255, SkPorterDuff::kClear_Mode);
432 PaintActiveTabBackground(canvas); 432 PaintActiveTabBackground(canvas);
433 canvas->restore(); 433 canvas->restore();
434 } 434 }
435 } 435 }
436 } 436 }
437 437
438 void TabRendererGtk::PaintInactiveTabBackground(ChromeCanvasPaint* canvas) { 438 void TabRendererGtk::PaintInactiveTabBackground(gfx::CanvasPaint* canvas) {
439 bool is_otr = data_.off_the_record; 439 bool is_otr = data_.off_the_record;
440 440
441 // The tab image needs to be lined up with the background image 441 // The tab image needs to be lined up with the background image
442 // so that it feels partially transparent. 442 // so that it feels partially transparent.
443 int offset = 1; 443 int offset = 1;
444 int offset_y = 20; 444 int offset_y = 20;
445 445
446 int tab_id = is_otr ? 446 int tab_id = is_otr ?
447 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND; 447 IDR_THEME_TAB_BACKGROUND_INCOGNITO : IDR_THEME_TAB_BACKGROUND;
448 448
(...skipping 30 matching lines...) Expand all
479 width() - tab_active_.l_width - tab_active_.r_width, height() - 3); 479 width() - tab_active_.l_width - tab_active_.r_width, height() - 3);
480 480
481 canvas->DrawBitmapInt(*tab_inactive_.image_l, bounds_.x(), bounds_.y()); 481 canvas->DrawBitmapInt(*tab_inactive_.image_l, bounds_.x(), bounds_.y());
482 canvas->TileImageInt(*tab_inactive_.image_c, tab_inactive_.l_width, 0, 482 canvas->TileImageInt(*tab_inactive_.image_c, tab_inactive_.l_width, 0,
483 bounds_.x() + width() - tab_inactive_.l_width - tab_inactive_.r_width, 483 bounds_.x() + width() - tab_inactive_.l_width - tab_inactive_.r_width,
484 bounds_.y() + height()); 484 bounds_.y() + height());
485 canvas->DrawBitmapInt(*tab_inactive_.image_r, 485 canvas->DrawBitmapInt(*tab_inactive_.image_r,
486 bounds_.x() + width() - tab_inactive_.r_width, bounds_.y()); 486 bounds_.x() + width() - tab_inactive_.r_width, bounds_.y());
487 } 487 }
488 488
489 void TabRendererGtk::PaintActiveTabBackground(ChromeCanvasPaint* canvas) { 489 void TabRendererGtk::PaintActiveTabBackground(gfx::CanvasPaint* canvas) {
490 int offset = 1; 490 int offset = 1;
491 491
492 SkBitmap* tab_bg = theme_provider_->GetBitmapNamed(IDR_THEME_TOOLBAR); 492 SkBitmap* tab_bg = theme_provider_->GetBitmapNamed(IDR_THEME_TOOLBAR);
493 493
494 // Draw left edge. 494 // Draw left edge.
495 SkBitmap tab_l = skia::ImageOperations::CreateTiledBitmap( 495 SkBitmap tab_l = skia::ImageOperations::CreateTiledBitmap(
496 *tab_bg, offset, 0, tab_active_.l_width, height()); 496 *tab_bg, offset, 0, tab_active_.l_width, height());
497 SkBitmap theme_l = skia::ImageOperations::CreateMaskedBitmap( 497 SkBitmap theme_l = skia::ImageOperations::CreateMaskedBitmap(
498 tab_l, *tab_alpha.image_l); 498 tab_l, *tab_alpha.image_l);
499 canvas->DrawBitmapInt(theme_l, bounds_.x(), bounds_.y()); 499 canvas->DrawBitmapInt(theme_l, bounds_.x(), bounds_.y());
(...skipping 15 matching lines...) Expand all
515 width() - tab_active_.l_width - tab_active_.r_width, height() - 2); 515 width() - tab_active_.l_width - tab_active_.r_width, height() - 2);
516 516
517 canvas->DrawBitmapInt(*tab_active_.image_l, bounds_.x(), bounds_.y()); 517 canvas->DrawBitmapInt(*tab_active_.image_l, bounds_.x(), bounds_.y());
518 canvas->TileImageInt(*tab_active_.image_c, 518 canvas->TileImageInt(*tab_active_.image_c,
519 bounds_.x() + tab_active_.l_width, bounds_.y(), 519 bounds_.x() + tab_active_.l_width, bounds_.y(),
520 width() - tab_active_.l_width - tab_active_.r_width, height()); 520 width() - tab_active_.l_width - tab_active_.r_width, height());
521 canvas->DrawBitmapInt(*tab_active_.image_r, 521 canvas->DrawBitmapInt(*tab_active_.image_r,
522 bounds_.x() + width() - tab_active_.r_width, bounds_.y()); 522 bounds_.x() + width() - tab_active_.r_width, bounds_.y());
523 } 523 }
524 524
525 void TabRendererGtk::PaintLoadingAnimation(ChromeCanvasPaint* canvas) { 525 void TabRendererGtk::PaintLoadingAnimation(gfx::CanvasPaint* canvas) {
526 const SkBitmap* frames = 526 const SkBitmap* frames =
527 (loading_animation_.animation_state() == ANIMATION_WAITING) ? 527 (loading_animation_.animation_state() == ANIMATION_WAITING) ?
528 loading_animation_.waiting_animation_frames() : 528 loading_animation_.waiting_animation_frames() :
529 loading_animation_.loading_animation_frames(); 529 loading_animation_.loading_animation_frames();
530 const int image_size = frames->height(); 530 const int image_size = frames->height();
531 const int image_offset = loading_animation_.animation_frame() * image_size; 531 const int image_offset = loading_animation_.animation_frame() * image_size;
532 const int dst_y = (height() - image_size) / 2; 532 const int dst_y = (height() - image_size) / 2;
533 533
534 // Just like with the Tab's title and favicon, the position for the page 534 // Just like with the Tab's title and favicon, the position for the page
535 // loading animation also needs to be mirrored if the UI layout is RTL. 535 // loading animation also needs to be mirrored if the UI layout is RTL.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 LoadTabImages(); 589 LoadTabImages();
590 590
591 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 591 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
592 title_font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont)); 592 title_font_ = new gfx::Font(rb.GetFont(ResourceBundle::BaseFont));
593 title_font_height_ = title_font_->height(); 593 title_font_height_ = title_font_->height();
594 594
595 InitializeLoadingAnimationData(&rb, &loading_animation_data); 595 InitializeLoadingAnimationData(&rb, &loading_animation_data);
596 596
597 initialized_ = true; 597 initialized_ = true;
598 } 598 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/tabs/tab_renderer_gtk.h ('k') | chrome/browser/gtk/tabs/tab_strip_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698