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