OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/tabs/dragged_tab_view.h" | 5 #include "chrome/browser/views/tabs/dragged_tab_view.h" |
6 | 6 |
7 #include "chrome/common/gfx/chrome_canvas.h" | 7 #include "chrome/common/gfx/chrome_canvas.h" |
8 #include "chrome/browser/tab_contents.h" | 8 #include "chrome/browser/tab_contents.h" |
9 #include "chrome/browser/tabs/tab_strip_model.h" | 9 #include "chrome/browser/tabs/tab_strip_model.h" |
10 #include "chrome/browser/views/tabs/hwnd_photobooth.h" | 10 #include "chrome/browser/views/tabs/hwnd_photobooth.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 void DraggedTabView::MoveTo(const gfx::Point& screen_point) { | 57 void DraggedTabView::MoveTo(const gfx::Point& screen_point) { |
58 if (!container_->IsVisible()) | 58 if (!container_->IsVisible()) |
59 container_->ShowWindow(SW_SHOWNOACTIVATE); | 59 container_->ShowWindow(SW_SHOWNOACTIVATE); |
60 | 60 |
61 int x; | 61 int x; |
62 if (UILayoutIsRightToLeft() && !attached_) { | 62 if (UILayoutIsRightToLeft() && !attached_) { |
63 // On RTL locales, a dragged tab (when it is not attached to a tab strip) | 63 // On RTL locales, a dragged tab (when it is not attached to a tab strip) |
64 // is rendered using a right-to-left orientation so we should calculate the | 64 // is rendered using a right-to-left orientation so we should calculate the |
65 // window position differently. | 65 // window position differently. |
66 CSize ps; | 66 gfx::Size ps = GetPreferredSize(); |
67 GetPreferredSize(&ps); | 67 x = screen_point.x() - ScaleValue(ps.width()) + mouse_tab_offset_.x() + |
68 x = screen_point.x() - ScaleValue(ps.cx) + mouse_tab_offset_.x() + | |
69 ScaleValue( | 68 ScaleValue( |
70 renderer_->MirroredXCoordinateInsideView(mouse_tab_offset_.x())); | 69 renderer_->MirroredXCoordinateInsideView(mouse_tab_offset_.x())); |
71 } else { | 70 } else { |
72 x = screen_point.x() + mouse_tab_offset_.x() - | 71 x = screen_point.x() + mouse_tab_offset_.x() - |
73 ScaleValue(mouse_tab_offset_.x()); | 72 ScaleValue(mouse_tab_offset_.x()); |
74 } | 73 } |
75 int y = screen_point.y() + mouse_tab_offset_.y() - | 74 int y = screen_point.y() + mouse_tab_offset_.y() - |
76 ScaleValue(mouse_tab_offset_.y()); | 75 ScaleValue(mouse_tab_offset_.y()); |
77 | 76 |
78 container_->SetWindowPos(NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE); | 77 container_->SetWindowPos(NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 142 |
144 void DraggedTabView::Paint(ChromeCanvas* canvas) { | 143 void DraggedTabView::Paint(ChromeCanvas* canvas) { |
145 if (attached_) { | 144 if (attached_) { |
146 PaintAttachedTab(canvas); | 145 PaintAttachedTab(canvas); |
147 } else { | 146 } else { |
148 PaintDetachedView(canvas); | 147 PaintDetachedView(canvas); |
149 } | 148 } |
150 } | 149 } |
151 | 150 |
152 void DraggedTabView::Layout() { | 151 void DraggedTabView::Layout() { |
153 CSize ps; | |
154 GetPreferredSize(&ps); | |
155 if (attached_) { | 152 if (attached_) { |
156 renderer_->SetBounds(CRect(0, 0, ps.cx, ps.cy)); | 153 renderer_->SetBounds(gfx::Point(), GetPreferredSize()); |
157 } else { | 154 } else { |
158 int left = 0; | 155 int left = 0; |
159 if (UILayoutIsRightToLeft()) | 156 if (UILayoutIsRightToLeft()) |
160 left = ps.cx - attached_tab_size_.width(); | 157 left = GetPreferredSize().width() - attached_tab_size_.width(); |
161 renderer_->SetBounds(CRect(left, 0, left + attached_tab_size_.width(), | 158 renderer_->SetBounds(CRect(left, 0, left + attached_tab_size_.width(), |
162 attached_tab_size_.height())); | 159 attached_tab_size_.height())); |
163 } | 160 } |
164 } | 161 } |
165 | 162 |
166 void DraggedTabView::GetPreferredSize(CSize* out) { | 163 gfx::Size DraggedTabView::GetPreferredSize() { |
167 DCHECK(out); | 164 if (attached_) |
168 if (attached_) { | 165 return attached_tab_size_; |
169 *out = attached_tab_size_.ToSIZE(); | 166 |
170 } else { | 167 int width = std::max(attached_tab_size_.width(), contents_size_.width()) + |
171 int width = std::max(attached_tab_size_.width(), contents_size_.width()) + | 168 kTwiceDragFrameBorderSize; |
172 kTwiceDragFrameBorderSize; | 169 int height = attached_tab_size_.height() + kDragFrameBorderSize + |
173 int height = attached_tab_size_.height() + kDragFrameBorderSize + | 170 contents_size_.height(); |
174 contents_size_.height(); | 171 return gfx::Size(width, height); |
175 *out = CSize(width, height); | |
176 } | |
177 } | 172 } |
178 | 173 |
179 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
180 // DraggedTabView, private: | 175 // DraggedTabView, private: |
181 | 176 |
182 void DraggedTabView::PaintAttachedTab(ChromeCanvas* canvas) { | 177 void DraggedTabView::PaintAttachedTab(ChromeCanvas* canvas) { |
183 renderer_->ProcessPaint(canvas); | 178 renderer_->ProcessPaint(canvas); |
184 } | 179 } |
185 | 180 |
186 void DraggedTabView::PaintDetachedView(ChromeCanvas* canvas) { | 181 void DraggedTabView::PaintDetachedView(ChromeCanvas* canvas) { |
187 CSize ps; | 182 gfx::Size ps = GetPreferredSize(); |
188 GetPreferredSize(&ps); | 183 ChromeCanvas scale_canvas(ps.width(), ps.height(), false); |
189 ChromeCanvas scale_canvas(ps.cx, ps.cy, false); | |
190 SkBitmap& bitmap_device = const_cast<SkBitmap&>( | 184 SkBitmap& bitmap_device = const_cast<SkBitmap&>( |
191 scale_canvas.getTopPlatformDevice().accessBitmap(true)); | 185 scale_canvas.getTopPlatformDevice().accessBitmap(true)); |
192 bitmap_device.eraseARGB(0, 0, 0, 0); | 186 bitmap_device.eraseARGB(0, 0, 0, 0); |
193 | 187 |
194 scale_canvas.FillRectInt(kDraggedTabBorderColor, 0, | 188 scale_canvas.FillRectInt(kDraggedTabBorderColor, 0, |
195 attached_tab_size_.height() - kDragFrameBorderSize, | 189 attached_tab_size_.height() - kDragFrameBorderSize, |
196 ps.cx, ps.cy - attached_tab_size_.height()); | 190 ps.width(), ps.height() - attached_tab_size_.height()); |
197 int image_x = kDragFrameBorderSize; | 191 int image_x = kDragFrameBorderSize; |
198 int image_y = attached_tab_size_.height(); | 192 int image_y = attached_tab_size_.height(); |
199 int image_w = ps.cx - kTwiceDragFrameBorderSize; | 193 int image_w = ps.width() - kTwiceDragFrameBorderSize; |
200 int image_h = | 194 int image_h = |
201 ps.cy - kTwiceDragFrameBorderSize - attached_tab_size_.height(); | 195 ps.height() - kTwiceDragFrameBorderSize - attached_tab_size_.height(); |
202 scale_canvas.FillRectInt(SK_ColorBLACK, image_x, image_y, image_w, image_h); | 196 scale_canvas.FillRectInt(SK_ColorBLACK, image_x, image_y, image_w, image_h); |
203 photobooth_->PaintScreenshotIntoCanvas( | 197 photobooth_->PaintScreenshotIntoCanvas( |
204 &scale_canvas, | 198 &scale_canvas, |
205 gfx::Rect(image_x, image_y, image_w, image_h)); | 199 gfx::Rect(image_x, image_y, image_w, image_h)); |
206 renderer_->ProcessPaint(&scale_canvas); | 200 renderer_->ProcessPaint(&scale_canvas); |
207 | 201 |
208 SkIRect subset; | 202 SkIRect subset; |
209 subset.set(0, 0, ps.cx, ps.cy); | 203 subset.set(0, 0, ps.width(), ps.height()); |
210 SkBitmap mipmap = scale_canvas.ExtractBitmap(); | 204 SkBitmap mipmap = scale_canvas.ExtractBitmap(); |
211 mipmap.buildMipMap(true); | 205 mipmap.buildMipMap(true); |
212 | 206 |
213 SkShader* bitmap_shader = | 207 SkShader* bitmap_shader = |
214 SkShader::CreateBitmapShader(mipmap, SkShader::kClamp_TileMode, | 208 SkShader::CreateBitmapShader(mipmap, SkShader::kClamp_TileMode, |
215 SkShader::kClamp_TileMode); | 209 SkShader::kClamp_TileMode); |
216 | 210 |
217 SkMatrix shader_scale; | 211 SkMatrix shader_scale; |
218 shader_scale.setScale(kScalingFactor, kScalingFactor); | 212 shader_scale.setScale(kScalingFactor, kScalingFactor); |
219 bitmap_shader->setLocalMatrix(shader_scale); | 213 bitmap_shader->setLocalMatrix(shader_scale); |
220 | 214 |
221 SkPaint paint; | 215 SkPaint paint; |
222 paint.setShader(bitmap_shader); | 216 paint.setShader(bitmap_shader); |
223 paint.setAntiAlias(true); | 217 paint.setAntiAlias(true); |
224 bitmap_shader->unref(); | 218 bitmap_shader->unref(); |
225 | 219 |
226 SkRect rc; | 220 SkRect rc; |
227 rc.fLeft = 0; | 221 rc.fLeft = 0; |
228 rc.fTop = 0; | 222 rc.fTop = 0; |
229 rc.fRight = SkIntToScalar(ps.cx); | 223 rc.fRight = SkIntToScalar(ps.width()); |
230 rc.fBottom = SkIntToScalar(ps.cy); | 224 rc.fBottom = SkIntToScalar(ps.height()); |
231 canvas->drawRect(rc, paint); | 225 canvas->drawRect(rc, paint); |
232 } | 226 } |
233 | 227 |
234 void DraggedTabView::ResizeContainer() { | 228 void DraggedTabView::ResizeContainer() { |
235 CSize ps; | 229 gfx::Size ps = GetPreferredSize(); |
236 GetPreferredSize(&ps); | 230 SetWindowPos(container_->GetHWND(), HWND_TOPMOST, 0, 0, |
237 SetWindowPos(container_->GetHWND(), HWND_TOPMOST, 0, 0, ScaleValue(ps.cx), | 231 ScaleValue(ps.width()), ScaleValue(ps.height()), |
238 ScaleValue(ps.cy), SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); | 232 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); |
239 } | 233 } |
240 | 234 |
241 int DraggedTabView::ScaleValue(int value) { | 235 int DraggedTabView::ScaleValue(int value) { |
242 return attached_ ? value : static_cast<int>(value * kScalingFactor); | 236 return attached_ ? value : static_cast<int>(value * kScalingFactor); |
243 } | 237 } |
244 | 238 |
OLD | NEW |