Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2011 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/ui/views/theme_background.h"
      6 
      7 #include "chrome/browser/profiles/profile.h"
      8 #include "chrome/browser/themes/theme_service.h"
      9 #include "chrome/browser/themes/theme_service_factory.h"
     10 #include "chrome/browser/ui/views/frame/browser_view.h"
     11 #include "grit/app_resources.h"
     12 #include "grit/generated_resources.h"
     13 #include "grit/theme_resources.h"
     14 #include "ui/base/resource/resource_bundle.h"
     15 #include "ui/gfx/canvas.h"
     16 #include "views/view.h"
     17 
     18 ThemeBackground::ThemeBackground(BrowserView* browser_view)
     19     : browser_view_(browser_view) {
     20 }
     21 
     22 void ThemeBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
     23   SkBitmap* background;
     24 
     25   // Never theme app and popup windows.
     26   if (!browser_view_->IsBrowserTypeNormal()) {
     27     ResourceBundle& rb = ResourceBundle::GetSharedInstance();
     28     if (browser_view_->IsActive())
     29       background = rb.GetBitmapNamed(IDR_FRAME);
     30     else
     31       background = rb.GetBitmapNamed(IDR_THEME_FRAME_INACTIVE);
     32   } else {
     33     Profile* profile = browser_view_->browser()->profile();
     34     ui::ThemeProvider* theme = ThemeServiceFactory::GetForProfile(profile);
     35 
     36     if (browser_view_->IsActive()) {
     37       background = theme->GetBitmapNamed(
     38           profile->IsOffTheRecord() ?
     39           IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME);
     40     } else {
     41       background = theme->GetBitmapNamed(
     42           profile->IsOffTheRecord() ?
     43           IDR_THEME_FRAME_INCOGNITO_INACTIVE : IDR_THEME_FRAME_INACTIVE);
     44     }
     45   }
     46 
     47   gfx::Point origin(0, 0);
     48   views::View::ConvertPointToView(view,
     49                                   browser_view_->frame()->GetFrameView(),
     50                                   &origin);
     51 #if defined(OS_CHROMEOS)
     52   const int kCustomFrameBackgroundVerticalOffset = 15;
     53   // TODO(oshima): Remove this once we fully migrated to views.
     54   // See http://crbug.com/28580.
     55   if (browser_view_->IsMaximized()) {
     56     origin.Offset(0, kCustomFrameBackgroundVerticalOffset + 1);
     57   }
     58 #endif
     59   canvas->TileImageInt(*background,
     60                        origin.x(), origin.y(), 0, 0,
     61                        view->width(), view->height());
     62 }
     63