[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / ui / views / window / frame_background.cc
blobf9e8293c0db95441ad317c2f63d20a217ec61cf6
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
3 // found in the LICENSE file.
5 #include "ui/views/window/frame_background.h"
7 #include "grit/ui_resources.h"
8 #include "third_party/skia/include/core/SkCanvas.h"
9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/base/theme_provider.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/views/view.h"
14 namespace views {
16 FrameBackground::FrameBackground()
17 : frame_color_(0),
18 theme_image_(NULL),
19 theme_overlay_image_(NULL),
20 top_area_height_(0),
21 left_edge_(NULL),
22 top_edge_(NULL),
23 right_edge_(NULL),
24 bottom_edge_(NULL),
25 top_left_corner_(NULL),
26 top_right_corner_(NULL),
27 bottom_left_corner_(NULL),
28 bottom_right_corner_(NULL),
29 maximized_top_inset_(0) {
32 FrameBackground::~FrameBackground() {
35 void FrameBackground::SetSideImages(const gfx::ImageSkia* left,
36 const gfx::ImageSkia* top,
37 const gfx::ImageSkia* right,
38 const gfx::ImageSkia* bottom) {
39 left_edge_ = left;
40 top_edge_ = top;
41 right_edge_ = right;
42 bottom_edge_ = bottom;
45 void FrameBackground::SetCornerImages(const gfx::ImageSkia* top_left,
46 const gfx::ImageSkia* top_right,
47 const gfx::ImageSkia* bottom_left,
48 const gfx::ImageSkia* bottom_right) {
49 top_left_corner_ = top_left;
50 top_right_corner_ = top_right;
51 bottom_left_corner_ = bottom_left;
52 bottom_right_corner_ = bottom_right;
55 void FrameBackground::PaintRestored(gfx::Canvas* canvas, View* view) const {
56 // Fill with the frame color first so we have a constant background for
57 // areas not covered by the theme image.
58 PaintFrameColor(canvas, view);
60 // Draw the theme frame.
61 canvas->TileImageInt(*theme_image_,
62 0, 0, view->width(), theme_image_->height());
64 // Draw the theme frame overlay, if available.
65 if (theme_overlay_image_)
66 canvas->DrawImageInt(*theme_overlay_image_, 0, 0);
68 // Draw the top corners and edge, scaling the corner images down if they
69 // are too big and relative to the vertical space available.
70 int top_left_height =
71 std::min(top_left_corner_->height(),
72 view->height() - bottom_left_corner_->height());
73 canvas->DrawImageInt(*top_left_corner_,
74 0, 0, top_left_corner_->width(), top_left_height,
75 0, 0, top_left_corner_->width(), top_left_height,
76 false);
77 canvas->TileImageInt(*top_edge_,
78 top_left_corner_->width(),
80 view->width() - top_left_corner_->width() - top_right_corner_->width(),
81 top_edge_->height());
82 int top_right_height =
83 std::min(top_right_corner_->height(),
84 view->height() - bottom_right_corner_->height());
85 canvas->DrawImageInt(*top_right_corner_,
86 0, 0,
87 top_right_corner_->width(), top_right_height,
88 view->width() - top_right_corner_->width(), 0,
89 top_right_corner_->width(), top_right_height,
90 false);
92 // Right edge.
93 int right_edge_height =
94 view->height() - top_right_height - bottom_right_corner_->height();
95 canvas->TileImageInt(*right_edge_,
96 view->width() - right_edge_->width(),
97 top_right_height,
98 right_edge_->width(),
99 right_edge_height);
101 // Bottom corners and edge.
102 canvas->DrawImageInt(*bottom_right_corner_,
103 view->width() - bottom_right_corner_->width(),
104 view->height() - bottom_right_corner_->height());
105 canvas->TileImageInt(
106 *bottom_edge_,
107 bottom_left_corner_->width(),
108 view->height() - bottom_edge_->height(),
109 view->width() - bottom_left_corner_->width()
110 - bottom_right_corner_->width(),
111 bottom_edge_->height());
112 canvas->DrawImageInt(*bottom_left_corner_, 0,
113 view->height() - bottom_left_corner_->height());
115 // Left edge.
116 int left_edge_height =
117 view->height() - top_left_height - bottom_left_corner_->height();
118 canvas->TileImageInt(*left_edge_,
119 0, top_left_height,
120 left_edge_->width(), left_edge_height);
123 void FrameBackground::PaintMaximized(gfx::Canvas* canvas, View* view) const {
124 // We will be painting from -|maximized_top_inset_| to
125 // -|maximized_top_inset_| + |theme_image_|->height(). If this is less than
126 // |top_area_height_|, we need to paint the frame color to fill in the area
127 // beneath the image.
128 int theme_frame_bottom = -maximized_top_inset_ + theme_image_->height();
129 if (top_area_height_ > theme_frame_bottom) {
130 canvas->FillRect(gfx::Rect(0, 0, view->width(), top_area_height_),
131 frame_color_);
134 // Draw the theme frame.
135 canvas->TileImageInt(*theme_image_,
137 -maximized_top_inset_,
138 view->width(),
139 theme_image_->height());
140 // Draw the theme frame overlay, if available.
141 if (theme_overlay_image_)
142 canvas->DrawImageInt(*theme_overlay_image_, 0, -maximized_top_inset_);
145 void FrameBackground::PaintFrameColor(gfx::Canvas* canvas, View* view) const {
146 // Fill the top area.
147 canvas->FillRect(gfx::Rect(0, 0, view->width(), top_area_height_),
148 frame_color_);
150 // If the window is very short, we're done.
151 int remaining_height = view->height() - top_area_height_;
152 if (remaining_height <= 0)
153 return;
155 // Fill down the sides.
156 canvas->FillRect(gfx::Rect(0, top_area_height_, left_edge_->width(),
157 remaining_height), frame_color_);
158 canvas->FillRect(gfx::Rect(view->width() - right_edge_->width(),
159 top_area_height_, right_edge_->width(),
160 remaining_height), frame_color_);
162 // If the window is very narrow, we're done.
163 int center_width =
164 view->width() - left_edge_->width() - right_edge_->width();
165 if (center_width <= 0)
166 return;
168 // Fill the bottom area.
169 canvas->FillRect(gfx::Rect(left_edge_->width(),
170 view->height() - bottom_edge_->height(),
171 center_width, bottom_edge_->height()),
172 frame_color_);
175 } // namespace views