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

Side by Side Diff: chrome/browser/views/constrained_window_impl.cc

Issue 27317: Support DWM switching.... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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
OLDNEW
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/constrained_window_impl.h" 5 #include "chrome/browser/views/constrained_window_impl.h"
6 6
7 #include "base/gfx/rect.h" 7 #include "base/gfx/rect.h"
8 #include "chrome/app/chrome_dll_resource.h" 8 #include "chrome/app/chrome_dll_resource.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profile.h" 10 #include "chrome/browser/profile.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 static SkBitmap* bitmaps_[FRAME_PART_BITMAP_COUNT]; 177 static SkBitmap* bitmaps_[FRAME_PART_BITMAP_COUNT];
178 178
179 DISALLOW_EVIL_CONSTRUCTORS(OTRWindowResources); 179 DISALLOW_EVIL_CONSTRUCTORS(OTRWindowResources);
180 }; 180 };
181 181
182 SkBitmap* XPWindowResources::bitmaps_[]; 182 SkBitmap* XPWindowResources::bitmaps_[];
183 SkBitmap* VistaWindowResources::bitmaps_[]; 183 SkBitmap* VistaWindowResources::bitmaps_[];
184 SkBitmap* OTRWindowResources::bitmaps_[]; 184 SkBitmap* OTRWindowResources::bitmaps_[];
185 185
186 //////////////////////////////////////////////////////////////////////////////// 186 ////////////////////////////////////////////////////////////////////////////////
187 // ConstrainedWindowNonClientView 187 // ConstrainedWindowFrameView
188 188
189 class ConstrainedWindowNonClientView 189 class ConstrainedWindowFrameView
190 : public views::NonClientView, 190 : public views::NonClientFrameView,
191 public views::BaseButton::ButtonListener { 191 public views::BaseButton::ButtonListener {
192 public: 192 public:
193 ConstrainedWindowNonClientView(ConstrainedWindowImpl* container, 193 explicit ConstrainedWindowFrameView(ConstrainedWindowImpl* container);
194 TabContents* owner); 194 virtual ~ConstrainedWindowFrameView();
195 virtual ~ConstrainedWindowNonClientView();
196 195
197 void UpdateWindowTitle(); 196 void UpdateWindowTitle();
198 197
199 // Overridden from views::NonClientView: 198 // Overridden from views::NonClientFrameView:
200 virtual gfx::Rect CalculateClientAreaBounds(int width, int height) const; 199 virtual gfx::Rect GetBoundsForClientView() const;
201 virtual gfx::Size CalculateWindowSizeForClientSize(int width, 200 virtual bool AlwaysUseCustomFrame() const;
202 int height) const; 201 virtual gfx::Rect GetWindowBoundsForClientBounds(
202 const gfx::Rect& client_bounds) const;
203 virtual gfx::Point GetSystemMenuPoint() const; 203 virtual gfx::Point GetSystemMenuPoint() const;
204 virtual int NonClientHitTest(const gfx::Point& point); 204 virtual int NonClientHitTest(const gfx::Point& point);
205 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask); 205 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
206 virtual void EnableClose(bool enable); 206 virtual void EnableClose(bool enable);
207 virtual void ResetWindowControls() { } 207 virtual void ResetWindowControls() { }
208 208
209 // Overridden from views::View: 209 // Overridden from views::View:
210 virtual void Paint(ChromeCanvas* canvas); 210 virtual void Paint(ChromeCanvas* canvas);
211 virtual void Layout(); 211 virtual void Layout();
212 virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); 212 virtual void ThemeChanged();
213 213
214 // Overridden from views::BaseButton::ButtonListener: 214 // Overridden from views::BaseButton::ButtonListener:
215 virtual void ButtonPressed(views::BaseButton* sender); 215 virtual void ButtonPressed(views::BaseButton* sender);
216 216
217 private: 217 private:
218 // Returns the thickness of the border that makes up the window frame edges. 218 // Returns the thickness of the border that makes up the window frame edges.
219 // This does not include any client edge. 219 // This does not include any client edge.
220 int FrameBorderThickness() const; 220 int FrameBorderThickness() const;
221 221
222 // Returns the thickness of the entire nonclient left, right, and bottom 222 // Returns the thickness of the entire nonclient left, right, and bottom
(...skipping 12 matching lines...) Expand all
235 // Paints different parts of the window to the incoming canvas. 235 // Paints different parts of the window to the incoming canvas.
236 void PaintFrameBorder(ChromeCanvas* canvas); 236 void PaintFrameBorder(ChromeCanvas* canvas);
237 void PaintTitleBar(ChromeCanvas* canvas); 237 void PaintTitleBar(ChromeCanvas* canvas);
238 void PaintClientEdge(ChromeCanvas* canvas); 238 void PaintClientEdge(ChromeCanvas* canvas);
239 239
240 // Layout various sub-components of this view. 240 // Layout various sub-components of this view.
241 void LayoutWindowControls(); 241 void LayoutWindowControls();
242 void LayoutTitleBar(); 242 void LayoutTitleBar();
243 void LayoutClientView(); 243 void LayoutClientView();
244 244
245 // Returns the bounds of the client area for the specified view size.
246 gfx::Rect CalculateClientAreaBounds(int width, int height) const;
247
245 SkColor GetTitleColor() const { 248 SkColor GetTitleColor() const {
246 return (container_->owner()->profile()->IsOffTheRecord() || 249 return (container_->owner()->profile()->IsOffTheRecord() ||
247 !win_util::ShouldUseVistaFrame()) ? SK_ColorWHITE : SK_ColorBLACK; 250 !win_util::ShouldUseVistaFrame()) ? SK_ColorWHITE : SK_ColorBLACK;
248 } 251 }
249 252
253 // Loads the appropriate set of WindowResources for the frame view.
254 void InitWindowResources();
255
250 ConstrainedWindowImpl* container_; 256 ConstrainedWindowImpl* container_;
251 257
252 scoped_ptr<views::WindowResources> resources_; 258 scoped_ptr<views::WindowResources> resources_;
253 259
254 gfx::Rect title_bounds_; 260 gfx::Rect title_bounds_;
255 261
256 views::Button* close_button_; 262 views::Button* close_button_;
257 263
264 // The bounds of the ClientView.
265 gfx::Rect client_view_bounds_;
266
258 static void InitClass(); 267 static void InitClass();
259 268
260 // The font to be used to render the titlebar text. 269 // The font to be used to render the titlebar text.
261 static ChromeFont title_font_; 270 static ChromeFont title_font_;
262 271
263 DISALLOW_EVIL_CONSTRUCTORS(ConstrainedWindowNonClientView); 272 DISALLOW_EVIL_CONSTRUCTORS(ConstrainedWindowFrameView);
264 }; 273 };
265 274
266 ChromeFont ConstrainedWindowNonClientView::title_font_; 275 ChromeFont ConstrainedWindowFrameView::title_font_;
267 276
268 namespace { 277 namespace {
269 // The frame border is only visible in restored mode and is hardcoded to 4 px on 278 // The frame border is only visible in restored mode and is hardcoded to 4 px on
270 // each side regardless of the system window border size. 279 // each side regardless of the system window border size.
271 const int kFrameBorderThickness = 4; 280 const int kFrameBorderThickness = 4;
272 // Various edges of the frame border have a 1 px shadow along their edges; in a 281 // Various edges of the frame border have a 1 px shadow along their edges; in a
273 // few cases we shift elements based on this amount for visual appeal. 282 // few cases we shift elements based on this amount for visual appeal.
274 const int kFrameShadowThickness = 1; 283 const int kFrameShadowThickness = 1;
275 // In the window corners, the resize areas don't actually expand bigger, but the 284 // In the window corners, the resize areas don't actually expand bigger, but the
276 // 16 px at the end of each edge triggers diagonal resizing. 285 // 16 px at the end of each edge triggers diagonal resizing.
(...skipping 10 matching lines...) Expand all
287 // The caption buttons are always drawn 1 px down from the visible top of the 296 // The caption buttons are always drawn 1 px down from the visible top of the
288 // window (the true top in restored mode, or the top of the screen in maximized 297 // window (the true top in restored mode, or the top of the screen in maximized
289 // mode). 298 // mode).
290 const int kCaptionTopSpacing = 1; 299 const int kCaptionTopSpacing = 1;
291 300
292 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0); 301 const SkColor kContentsBorderShadow = SkColorSetARGB(51, 0, 0, 0);
293 const SkColor kContentsBorderColor = SkColorSetRGB(219, 235, 255); 302 const SkColor kContentsBorderColor = SkColorSetRGB(219, 235, 255);
294 } 303 }
295 304
296 //////////////////////////////////////////////////////////////////////////////// 305 ////////////////////////////////////////////////////////////////////////////////
297 // ConstrainedWindowNonClientView, public: 306 // ConstrainedWindowFrameView, public:
298 307
299 ConstrainedWindowNonClientView::ConstrainedWindowNonClientView( 308 ConstrainedWindowFrameView::ConstrainedWindowFrameView(
300 ConstrainedWindowImpl* container, TabContents* owner) 309 ConstrainedWindowImpl* container)
301 : NonClientView(), 310 : NonClientFrameView(),
302 container_(container), 311 container_(container),
303 close_button_(new views::Button) { 312 close_button_(new views::Button) {
304 InitClass(); 313 InitClass();
305 if (owner->profile()->IsOffTheRecord()) { 314 InitWindowResources();
306 resources_.reset(new OTRWindowResources);
307 } else {
308 if (win_util::ShouldUseVistaFrame()) {
309 resources_.reset(new VistaWindowResources);
310 } else {
311 resources_.reset(new XPWindowResources);
312 }
313 }
314 315
315 close_button_->SetImage(views::Button::BS_NORMAL, 316 close_button_->SetImage(views::Button::BS_NORMAL,
316 resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON)); 317 resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON));
317 close_button_->SetImage(views::Button::BS_HOT, 318 close_button_->SetImage(views::Button::BS_HOT,
318 resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_H)); 319 resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_H));
319 close_button_->SetImage(views::Button::BS_PUSHED, 320 close_button_->SetImage(views::Button::BS_PUSHED,
320 resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_P)); 321 resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_P));
321 close_button_->SetImageAlignment(views::Button::ALIGN_CENTER, 322 close_button_->SetImageAlignment(views::Button::ALIGN_CENTER,
322 views::Button::ALIGN_MIDDLE); 323 views::Button::ALIGN_MIDDLE);
323 close_button_->SetListener(this, 0); 324 close_button_->SetListener(this, 0);
324 AddChildView(close_button_); 325 AddChildView(close_button_);
325 } 326 }
326 327
327 ConstrainedWindowNonClientView::~ConstrainedWindowNonClientView() { 328 ConstrainedWindowFrameView::~ConstrainedWindowFrameView() {
328 } 329 }
329 330
330 void ConstrainedWindowNonClientView::UpdateWindowTitle() { 331 void ConstrainedWindowFrameView::UpdateWindowTitle() {
331 SchedulePaint(title_bounds_, false); 332 SchedulePaint(title_bounds_, false);
332 } 333 }
333 334
334 //////////////////////////////////////////////////////////////////////////////// 335 ////////////////////////////////////////////////////////////////////////////////
335 // ConstrainedWindowNonClientView, views::NonClientView implementation: 336 // ConstrainedWindowFrameView, views::NonClientFrameView implementation:
336 337
337 gfx::Rect ConstrainedWindowNonClientView::CalculateClientAreaBounds( 338 gfx::Rect ConstrainedWindowFrameView::GetBoundsForClientView() const {
338 int width, 339 return client_view_bounds_;
339 int height) const { 340 }
341
342 bool ConstrainedWindowFrameView::AlwaysUseCustomFrame() const {
343 // Constrained windows always use the custom frame - they just have a
344 // different set of bitmaps.
345 return true;
346 }
347
348 gfx::Rect ConstrainedWindowFrameView::GetWindowBoundsForClientBounds(
349 const gfx::Rect& client_bounds) const {
340 int top_height = NonClientTopBorderHeight(); 350 int top_height = NonClientTopBorderHeight();
341 int border_thickness = NonClientBorderThickness(); 351 int border_thickness = NonClientBorderThickness();
342 return gfx::Rect(border_thickness, top_height, 352 return gfx::Rect(std::max(0, client_bounds.x() - border_thickness),
343 std::max(0, width - (2 * border_thickness)), 353 std::max(0, client_bounds.y() - top_height),
344 std::max(0, height - top_height - border_thickness)); 354 client_bounds.width() + (2 * border_thickness),
355 client_bounds.height() + top_height + border_thickness);
345 } 356 }
346 357
347 gfx::Size ConstrainedWindowNonClientView::CalculateWindowSizeForClientSize( 358 gfx::Point ConstrainedWindowFrameView::GetSystemMenuPoint() const {
348 int width,
349 int height) const {
350 int border_thickness = NonClientBorderThickness();
351 return gfx::Size(width + (2 * border_thickness),
352 height + NonClientTopBorderHeight() + border_thickness);
353 }
354
355 gfx::Point ConstrainedWindowNonClientView::GetSystemMenuPoint() const {
356 // Doesn't really matter, since we never show system menus on constrained 359 // Doesn't really matter, since we never show system menus on constrained
357 // windows... 360 // windows...
358 gfx::Point system_menu_point(FrameBorderThickness(), 361 gfx::Point system_menu_point(FrameBorderThickness(),
359 NonClientTopBorderHeight()); 362 NonClientTopBorderHeight());
360 ConvertPointToScreen(this, &system_menu_point); 363 ConvertPointToScreen(this, &system_menu_point);
361 return system_menu_point; 364 return system_menu_point;
362 } 365 }
363 366
364 int ConstrainedWindowNonClientView::NonClientHitTest(const gfx::Point& point) { 367 int ConstrainedWindowFrameView::NonClientHitTest(const gfx::Point& point) {
365 if (!bounds().Contains(point)) 368 if (!bounds().Contains(point))
366 return HTNOWHERE; 369 return HTNOWHERE;
367 370
368 int frame_component = container_->client_view()->NonClientHitTest(point); 371 int frame_component = container_->client_view()->NonClientHitTest(point);
369 if (frame_component != HTNOWHERE) 372 if (frame_component != HTNOWHERE)
370 return frame_component; 373 return frame_component;
371 374
372 // Then see if the point is within any of the window controls. 375 // Then see if the point is within any of the window controls.
373 if (close_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point)) 376 if (close_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(point))
374 return HTCLOSE; 377 return HTCLOSE;
375 378
376 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), 379 int window_component = GetHTComponentForFrame(point, FrameBorderThickness(),
377 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, 380 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize,
378 container_->window_delegate()->CanResize()); 381 container_->window_delegate()->CanResize());
379 // Fall back to the caption if no other component matches. 382 // Fall back to the caption if no other component matches.
380 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 383 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
381 } 384 }
382 385
383 void ConstrainedWindowNonClientView::GetWindowMask(const gfx::Size& size, 386 void ConstrainedWindowFrameView::GetWindowMask(const gfx::Size& size,
384 gfx::Path* window_mask) { 387 gfx::Path* window_mask) {
385 DCHECK(window_mask); 388 DCHECK(window_mask);
386 389
387 // Redefine the window visible region for the new size. 390 // Redefine the window visible region for the new size.
388 window_mask->moveTo(0, 3); 391 window_mask->moveTo(0, 3);
389 window_mask->lineTo(1, 2); 392 window_mask->lineTo(1, 2);
390 window_mask->lineTo(1, 1); 393 window_mask->lineTo(1, 1);
391 window_mask->lineTo(2, 1); 394 window_mask->lineTo(2, 1);
392 window_mask->lineTo(3, 0); 395 window_mask->lineTo(3, 0);
393 396
394 window_mask->lineTo(SkIntToScalar(size.width() - 3), 0); 397 window_mask->lineTo(SkIntToScalar(size.width() - 3), 0);
395 window_mask->lineTo(SkIntToScalar(size.width() - 2), 1); 398 window_mask->lineTo(SkIntToScalar(size.width() - 2), 1);
396 window_mask->lineTo(SkIntToScalar(size.width() - 1), 1); 399 window_mask->lineTo(SkIntToScalar(size.width() - 1), 1);
397 window_mask->lineTo(SkIntToScalar(size.width() - 1), 2); 400 window_mask->lineTo(SkIntToScalar(size.width() - 1), 2);
398 window_mask->lineTo(SkIntToScalar(size.width()), 3); 401 window_mask->lineTo(SkIntToScalar(size.width()), 3);
399 402
400 window_mask->lineTo(SkIntToScalar(size.width()), 403 window_mask->lineTo(SkIntToScalar(size.width()),
401 SkIntToScalar(size.height())); 404 SkIntToScalar(size.height()));
402 window_mask->lineTo(0, SkIntToScalar(size.height())); 405 window_mask->lineTo(0, SkIntToScalar(size.height()));
403 window_mask->close(); 406 window_mask->close();
404 } 407 }
405 408
406 void ConstrainedWindowNonClientView::EnableClose(bool enable) { 409 void ConstrainedWindowFrameView::EnableClose(bool enable) {
407 close_button_->SetEnabled(enable); 410 close_button_->SetEnabled(enable);
408 } 411 }
409 412
410 //////////////////////////////////////////////////////////////////////////////// 413 ////////////////////////////////////////////////////////////////////////////////
411 // ConstrainedWindowNonClientView, views::View implementation: 414 // ConstrainedWindowFrameView, views::View implementation:
412 415
413 void ConstrainedWindowNonClientView::Paint(ChromeCanvas* canvas) { 416 void ConstrainedWindowFrameView::Paint(ChromeCanvas* canvas) {
414 PaintFrameBorder(canvas); 417 PaintFrameBorder(canvas);
415 PaintTitleBar(canvas); 418 PaintTitleBar(canvas);
416 PaintClientEdge(canvas); 419 PaintClientEdge(canvas);
417 } 420 }
418 421
419 void ConstrainedWindowNonClientView::Layout() { 422 void ConstrainedWindowFrameView::Layout() {
420 LayoutWindowControls(); 423 LayoutWindowControls();
421 LayoutTitleBar(); 424 LayoutTitleBar();
422 LayoutClientView(); 425 LayoutClientView();
423 } 426 }
424 427
425 void ConstrainedWindowNonClientView::ViewHierarchyChanged(bool is_add, 428 void ConstrainedWindowFrameView::ThemeChanged() {
426 View *parent, 429 InitWindowResources();
427 View *child) {
428 // Add our Client View as we are added to the Container so that if we are
429 // subsequently resized all the parent-child relationships are established.
430 if (is_add && GetWidget() && child == this)
431 AddChildView(container_->client_view());
432 } 430 }
433 431
434 //////////////////////////////////////////////////////////////////////////////// 432 ////////////////////////////////////////////////////////////////////////////////
435 // ConstrainedWindowNonClientView, views::BaseButton::Button 433 // ConstrainedWindowFrameView, views::BaseButton::Button
436 // implementation: 434 // implementation:
437 435
438 void ConstrainedWindowNonClientView::ButtonPressed(views::BaseButton* sender) { 436 void ConstrainedWindowFrameView::ButtonPressed(views::BaseButton* sender) {
439 if (sender == close_button_) 437 if (sender == close_button_)
440 container_->ExecuteSystemMenuCommand(SC_CLOSE); 438 container_->ExecuteSystemMenuCommand(SC_CLOSE);
441 } 439 }
442 440
443 //////////////////////////////////////////////////////////////////////////////// 441 ////////////////////////////////////////////////////////////////////////////////
444 // ConstrainedWindowNonClientView, private: 442 // ConstrainedWindowFrameView, private:
445 443
446 int ConstrainedWindowNonClientView::FrameBorderThickness() const { 444 int ConstrainedWindowFrameView::FrameBorderThickness() const {
447 return kFrameBorderThickness; 445 return kFrameBorderThickness;
448 } 446 }
449 447
450 int ConstrainedWindowNonClientView::NonClientBorderThickness() const { 448 int ConstrainedWindowFrameView::NonClientBorderThickness() const {
451 return FrameBorderThickness() + kClientEdgeThickness; 449 return FrameBorderThickness() + kClientEdgeThickness;
452 } 450 }
453 451
454 int ConstrainedWindowNonClientView::NonClientTopBorderHeight() const { 452 int ConstrainedWindowFrameView::NonClientTopBorderHeight() const {
455 int title_top_spacing, title_thickness; 453 int title_top_spacing, title_thickness;
456 return TitleCoordinates(&title_top_spacing, &title_thickness); 454 return TitleCoordinates(&title_top_spacing, &title_thickness);
457 } 455 }
458 456
459 int ConstrainedWindowNonClientView::TitleCoordinates( 457 int ConstrainedWindowFrameView::TitleCoordinates(
460 int* title_top_spacing, 458 int* title_top_spacing,
461 int* title_thickness) const { 459 int* title_thickness) const {
462 int frame_thickness = FrameBorderThickness(); 460 int frame_thickness = FrameBorderThickness();
463 int min_titlebar_height = kTitlebarMinimumHeight + frame_thickness; 461 int min_titlebar_height = kTitlebarMinimumHeight + frame_thickness;
464 *title_top_spacing = frame_thickness + kTitleTopSpacing; 462 *title_top_spacing = frame_thickness + kTitleTopSpacing;
465 // The bottom spacing should be the same apparent height as the top spacing, 463 // The bottom spacing should be the same apparent height as the top spacing,
466 // plus have the client edge tacked on. 464 // plus have the client edge tacked on.
467 int title_bottom_spacing = *title_top_spacing + kClientEdgeThickness; 465 int title_bottom_spacing = *title_top_spacing + kClientEdgeThickness;
468 *title_thickness = std::max(title_font_.height(), 466 *title_thickness = std::max(title_font_.height(),
469 min_titlebar_height - *title_top_spacing - title_bottom_spacing); 467 min_titlebar_height - *title_top_spacing - title_bottom_spacing);
470 return *title_top_spacing + *title_thickness + title_bottom_spacing; 468 return *title_top_spacing + *title_thickness + title_bottom_spacing;
471 } 469 }
472 470
473 void ConstrainedWindowNonClientView::PaintFrameBorder(ChromeCanvas* canvas) { 471 void ConstrainedWindowFrameView::PaintFrameBorder(ChromeCanvas* canvas) {
474 SkBitmap* top_left_corner = resources_->GetPartBitmap(FRAME_TOP_LEFT_CORNER); 472 SkBitmap* top_left_corner = resources_->GetPartBitmap(FRAME_TOP_LEFT_CORNER);
475 SkBitmap* top_right_corner = 473 SkBitmap* top_right_corner =
476 resources_->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); 474 resources_->GetPartBitmap(FRAME_TOP_RIGHT_CORNER);
477 SkBitmap* top_edge = resources_->GetPartBitmap(FRAME_TOP_EDGE); 475 SkBitmap* top_edge = resources_->GetPartBitmap(FRAME_TOP_EDGE);
478 SkBitmap* right_edge = resources_->GetPartBitmap(FRAME_RIGHT_EDGE); 476 SkBitmap* right_edge = resources_->GetPartBitmap(FRAME_RIGHT_EDGE);
479 SkBitmap* left_edge = resources_->GetPartBitmap(FRAME_LEFT_EDGE); 477 SkBitmap* left_edge = resources_->GetPartBitmap(FRAME_LEFT_EDGE);
480 SkBitmap* bottom_left_corner = 478 SkBitmap* bottom_left_corner =
481 resources_->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER); 479 resources_->GetPartBitmap(FRAME_BOTTOM_LEFT_CORNER);
482 SkBitmap* bottom_right_corner = 480 SkBitmap* bottom_right_corner =
483 resources_->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER); 481 resources_->GetPartBitmap(FRAME_BOTTOM_RIGHT_CORNER);
(...skipping 23 matching lines...) Expand all
507 bottom_edge->height()); 505 bottom_edge->height());
508 canvas->DrawBitmapInt(*bottom_left_corner, 0, 506 canvas->DrawBitmapInt(*bottom_left_corner, 0,
509 height() - bottom_left_corner->height()); 507 height() - bottom_left_corner->height());
510 508
511 // Left. 509 // Left.
512 canvas->TileImageInt(*left_edge, 0, top_left_corner->height(), 510 canvas->TileImageInt(*left_edge, 0, top_left_corner->height(),
513 left_edge->width(), 511 left_edge->width(),
514 height() - top_left_corner->height() - bottom_left_corner->height()); 512 height() - top_left_corner->height() - bottom_left_corner->height());
515 } 513 }
516 514
517 void ConstrainedWindowNonClientView::PaintTitleBar(ChromeCanvas* canvas) { 515 void ConstrainedWindowFrameView::PaintTitleBar(ChromeCanvas* canvas) {
518 canvas->DrawStringInt(container_->GetWindowTitle(), title_font_, 516 canvas->DrawStringInt(container_->GetWindowTitle(), title_font_,
519 GetTitleColor(), MirroredLeftPointForRect(title_bounds_), 517 GetTitleColor(), MirroredLeftPointForRect(title_bounds_),
520 title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); 518 title_bounds_.y(), title_bounds_.width(), title_bounds_.height());
521 } 519 }
522 520
523 void ConstrainedWindowNonClientView::PaintClientEdge(ChromeCanvas* canvas) { 521 void ConstrainedWindowFrameView::PaintClientEdge(ChromeCanvas* canvas) {
524 gfx::Rect client_edge_bounds(CalculateClientAreaBounds(width(), height())); 522 gfx::Rect client_edge_bounds(CalculateClientAreaBounds(width(), height()));
525 client_edge_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness); 523 client_edge_bounds.Inset(-kClientEdgeThickness, -kClientEdgeThickness);
526 gfx::Rect frame_shadow_bounds(client_edge_bounds); 524 gfx::Rect frame_shadow_bounds(client_edge_bounds);
527 frame_shadow_bounds.Inset(-kFrameShadowThickness, -kFrameShadowThickness); 525 frame_shadow_bounds.Inset(-kFrameShadowThickness, -kFrameShadowThickness);
528 526
529 canvas->FillRectInt(kContentsBorderShadow, frame_shadow_bounds.x(), 527 canvas->FillRectInt(kContentsBorderShadow, frame_shadow_bounds.x(),
530 frame_shadow_bounds.y(), frame_shadow_bounds.width(), 528 frame_shadow_bounds.y(), frame_shadow_bounds.width(),
531 frame_shadow_bounds.height()); 529 frame_shadow_bounds.height());
532 530
533 canvas->FillRectInt(kContentsBorderColor, client_edge_bounds.x(), 531 canvas->FillRectInt(kContentsBorderColor, client_edge_bounds.x(),
534 client_edge_bounds.y(), client_edge_bounds.width(), 532 client_edge_bounds.y(), client_edge_bounds.width(),
535 client_edge_bounds.height()); 533 client_edge_bounds.height());
536 } 534 }
537 535
538 void ConstrainedWindowNonClientView::LayoutWindowControls() { 536 void ConstrainedWindowFrameView::LayoutWindowControls() {
539 gfx::Size close_button_size = close_button_->GetPreferredSize(); 537 gfx::Size close_button_size = close_button_->GetPreferredSize();
540 close_button_->SetBounds( 538 close_button_->SetBounds(
541 width() - close_button_size.width() - FrameBorderThickness(), 539 width() - close_button_size.width() - FrameBorderThickness(),
542 kCaptionTopSpacing, close_button_size.width(), 540 kCaptionTopSpacing, close_button_size.width(),
543 close_button_size.height()); 541 close_button_size.height());
544 } 542 }
545 543
546 void ConstrainedWindowNonClientView::LayoutTitleBar() { 544 void ConstrainedWindowFrameView::LayoutTitleBar() {
547 // Size the title. 545 // Size the title.
548 int title_x = FrameBorderThickness() + kIconLeftSpacing; 546 int title_x = FrameBorderThickness() + kIconLeftSpacing;
549 int title_top_spacing, title_thickness; 547 int title_top_spacing, title_thickness;
550 TitleCoordinates(&title_top_spacing, &title_thickness); 548 TitleCoordinates(&title_top_spacing, &title_thickness);
551 title_bounds_.SetRect(title_x, 549 title_bounds_.SetRect(title_x,
552 title_top_spacing + ((title_thickness - title_font_.height()) / 2), 550 title_top_spacing + ((title_thickness - title_font_.height()) / 2),
553 std::max(0, close_button_->x() - kTitleCaptionSpacing - title_x), 551 std::max(0, close_button_->x() - kTitleCaptionSpacing - title_x),
554 title_font_.height()); 552 title_font_.height());
555 } 553 }
556 554
557 void ConstrainedWindowNonClientView::LayoutClientView() { 555 void ConstrainedWindowFrameView::LayoutClientView() {
558 container_->client_view()->SetBounds(CalculateClientAreaBounds(width(), 556 client_view_bounds_ = CalculateClientAreaBounds(width(), height());
559 height())); 557 }
558
559 gfx::Rect ConstrainedWindowFrameView::CalculateClientAreaBounds(
560 int width,
561 int height) const {
562 int top_height = NonClientTopBorderHeight();
563 int border_thickness = NonClientBorderThickness();
564 return gfx::Rect(border_thickness, top_height,
565 std::max(0, width - (2 * border_thickness)),
566 std::max(0, height - top_height - border_thickness));
567 }
568
569 void ConstrainedWindowFrameView::InitWindowResources() {
570 if (container_->owner()->profile()->IsOffTheRecord()) {
571 resources_.reset(new OTRWindowResources);
572 } else {
573 if (win_util::ShouldUseVistaFrame()) {
574 resources_.reset(new VistaWindowResources);
575 } else {
576 resources_.reset(new XPWindowResources);
577 }
578 }
560 } 579 }
561 580
562 // static 581 // static
563 void ConstrainedWindowNonClientView::InitClass() { 582 void ConstrainedWindowFrameView::InitClass() {
564 static bool initialized = false; 583 static bool initialized = false;
565 if (!initialized) { 584 if (!initialized) {
566 title_font_ = win_util::GetWindowTitleFont(); 585 title_font_ = win_util::GetWindowTitleFont();
567 586
568 initialized = true; 587 initialized = true;
569 } 588 }
570 } 589 }
571 590
572 //////////////////////////////////////////////////////////////////////////////// 591 ////////////////////////////////////////////////////////////////////////////////
573 // ConstrainedWindowImpl, public: 592 // ConstrainedWindowImpl, public:
574 593
575 // The space (in pixels) between minimized pop-ups stacked horizontally and 594 // The space (in pixels) between minimized pop-ups stacked horizontally and
576 // vertically. 595 // vertically.
577 static const int kPopupRepositionOffset = 5; 596 static const int kPopupRepositionOffset = 5;
578 static const int kConstrainedWindowEdgePadding = 10; 597 static const int kConstrainedWindowEdgePadding = 10;
579 598
580 ConstrainedWindowImpl::~ConstrainedWindowImpl() { 599 ConstrainedWindowImpl::~ConstrainedWindowImpl() {
581 } 600 }
582 601
583 //////////////////////////////////////////////////////////////////////////////// 602 ////////////////////////////////////////////////////////////////////////////////
584 // ConstrainedWindowImpl, ConstrainedWindow implementation: 603 // ConstrainedWindowImpl, ConstrainedWindow implementation:
585 604
586 ConstrainedWindowNonClientView* ConstrainedWindowImpl::non_client_view() { 605 views::NonClientFrameView* ConstrainedWindowImpl::CreateFrameViewForWindow() {
587 return static_cast<ConstrainedWindowNonClientView*>(non_client_view_); 606 return new ConstrainedWindowFrameView(this);
588 } 607 }
589 608
590 void ConstrainedWindowImpl::UpdateWindowTitle() { 609 void ConstrainedWindowImpl::UpdateWindowTitle() {
591 UpdateUI(TabContents::INVALIDATE_TITLE); 610 UpdateUI(TabContents::INVALIDATE_TITLE);
592 } 611 }
593 612
594 void ConstrainedWindowImpl::ActivateConstrainedWindow() { 613 void ConstrainedWindowImpl::ActivateConstrainedWindow() {
595 // Other pop-ups are simply moved to the front of the z-order. 614 // Other pop-ups are simply moved to the front of the z-order.
596 SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 615 SetWindowPos(HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
597 616
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 const gfx::Rect& ConstrainedWindowImpl::GetCurrentBounds() const { 664 const gfx::Rect& ConstrainedWindowImpl::GetCurrentBounds() const {
646 return current_bounds_; 665 return current_bounds_;
647 } 666 }
648 667
649 //////////////////////////////////////////////////////////////////////////////// 668 ////////////////////////////////////////////////////////////////////////////////
650 // ConstrainedWindowImpl, private: 669 // ConstrainedWindowImpl, private:
651 670
652 ConstrainedWindowImpl::ConstrainedWindowImpl( 671 ConstrainedWindowImpl::ConstrainedWindowImpl(
653 TabContents* owner, 672 TabContents* owner,
654 views::WindowDelegate* window_delegate) 673 views::WindowDelegate* window_delegate)
655 : CustomFrameWindow(window_delegate, 674 : Window(window_delegate),
656 new ConstrainedWindowNonClientView(this, owner)) { 675 owner_(owner) {
657 Init(owner); 676 non_client_view_->SetFrameView(CreateFrameViewForWindow());
677 Init();
658 } 678 }
659 679
660 void ConstrainedWindowImpl::Init(TabContents* owner) { 680 void ConstrainedWindowImpl::Init() {
661 owner_ = owner;
662 focus_restoration_disabled_ = false; 681 focus_restoration_disabled_ = false;
663 set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | 682 set_window_style(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION |
664 WS_THICKFRAME | WS_SYSMENU); 683 WS_THICKFRAME | WS_SYSMENU);
665 set_focus_on_creation(false); 684 set_focus_on_creation(false);
666 } 685 }
667 686
668 void ConstrainedWindowImpl::InitAsDialog(const gfx::Rect& initial_bounds) { 687 void ConstrainedWindowImpl::InitAsDialog(const gfx::Rect& initial_bounds) {
669 CustomFrameWindow::Init(owner_->GetNativeView(), initial_bounds); 688 Window::Init(owner_->GetNativeView(), initial_bounds);
670 ActivateConstrainedWindow(); 689 ActivateConstrainedWindow();
671 } 690 }
672 691
673 void ConstrainedWindowImpl::UpdateUI(unsigned int changed_flags) { 692 void ConstrainedWindowImpl::UpdateUI(unsigned int changed_flags) {
674 if (changed_flags & TabContents::INVALIDATE_TITLE) 693 if (changed_flags & TabContents::INVALIDATE_TITLE)
675 non_client_view()->UpdateWindowTitle(); 694 UpdateWindowTitle();
676 } 695 }
677 696
678 //////////////////////////////////////////////////////////////////////////////// 697 ////////////////////////////////////////////////////////////////////////////////
679 // ConstrainedWindowImpl, views::WidgetWin overrides: 698 // ConstrainedWindowImpl, views::WidgetWin overrides:
680 699
681 void ConstrainedWindowImpl::OnDestroy() { 700 void ConstrainedWindowImpl::OnDestroy() {
682 // We do this here, rather than |Close|, since the window may be destroyed in 701 // We do this here, rather than |Close|, since the window may be destroyed in
683 // a way other than by some other component calling Close, e.g. by the native 702 // a way other than by some other component calling Close, e.g. by the native
684 // window hierarchy closing. We are guaranteed to receive a WM_DESTROY 703 // window hierarchy closing. We are guaranteed to receive a WM_DESTROY
685 // message regardless of how the window is closed. 704 // message regardless of how the window is closed.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog( 758 ConstrainedWindow* ConstrainedWindow::CreateConstrainedDialog(
740 TabContents* parent, 759 TabContents* parent,
741 const gfx::Rect& initial_bounds, 760 const gfx::Rect& initial_bounds,
742 views::View* contents_view, 761 views::View* contents_view,
743 views::WindowDelegate* window_delegate) { 762 views::WindowDelegate* window_delegate) {
744 ConstrainedWindowImpl* window = new ConstrainedWindowImpl(parent, 763 ConstrainedWindowImpl* window = new ConstrainedWindowImpl(parent,
745 window_delegate); 764 window_delegate);
746 window->InitAsDialog(initial_bounds); 765 window->InitAsDialog(initial_bounds);
747 return window; 766 return window;
748 } 767 }
OLDNEW
« no previous file with comments | « chrome/browser/views/constrained_window_impl.h ('k') | chrome/browser/views/frame/aero_glass_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698