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

Side by Side Diff: chrome/browser/ui/views/frame/opaque_browser_frame_view.cc

Issue 5114001: Further cleanup of delegate==NULL cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Further cleanup of delegate == NULL cases. Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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/frame/opaque_browser_frame_view.h" 5 #include "chrome/browser/views/frame/opaque_browser_frame_view.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/theme_provider.h" 9 #include "app/theme_provider.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 window_icon_->Update(); 212 window_icon_->Update();
213 } 213 }
214 214
215 gfx::Size OpaqueBrowserFrameView::GetMinimumSize() { 215 gfx::Size OpaqueBrowserFrameView::GetMinimumSize() {
216 gfx::Size min_size(browser_view_->GetMinimumSize()); 216 gfx::Size min_size(browser_view_->GetMinimumSize());
217 int border_thickness = NonClientBorderThickness(); 217 int border_thickness = NonClientBorderThickness();
218 min_size.Enlarge(2 * border_thickness, 218 min_size.Enlarge(2 * border_thickness,
219 NonClientTopBorderHeight(false, false) + border_thickness); 219 NonClientTopBorderHeight(false, false) + border_thickness);
220 220
221 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate(); 221 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate();
222 if (delegate == NULL) {
223 LOG(INFO) << "delegate is NULL, returning safe default.";
224 return min_size;
225 }
226 int min_titlebar_width = (2 * FrameBorderThickness(false)) + 222 int min_titlebar_width = (2 * FrameBorderThickness(false)) +
227 kIconLeftSpacing + 223 kIconLeftSpacing +
228 (delegate->ShouldShowWindowIcon() ? (IconSize() + kTitleLogoSpacing) : 0); 224 (delegate && delegate->ShouldShowWindowIcon() ?
225 (IconSize() + kTitleLogoSpacing) : 0);
229 #if !defined(OS_CHROMEOS) 226 #if !defined(OS_CHROMEOS)
230 min_titlebar_width += 227 min_titlebar_width +=
231 minimize_button_->GetMinimumSize().width() + 228 minimize_button_->GetMinimumSize().width() +
232 restore_button_->GetMinimumSize().width() + 229 restore_button_->GetMinimumSize().width() +
233 close_button_->GetMinimumSize().width(); 230 close_button_->GetMinimumSize().width();
234 #endif 231 #endif
235 min_size.set_width(std::max(min_size.width(), min_titlebar_width)); 232 min_size.set_width(std::max(min_size.width(), min_titlebar_width));
236 return min_size; 233 return min_size;
237 } 234 }
238 235
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 maximize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( 291 maximize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(
295 point)) 292 point))
296 return HTMAXBUTTON; 293 return HTMAXBUTTON;
297 if (minimize_button_->IsVisible() && 294 if (minimize_button_->IsVisible() &&
298 minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains( 295 minimize_button_->GetBounds(APPLY_MIRRORING_TRANSFORMATION).Contains(
299 point)) 296 point))
300 return HTMINBUTTON; 297 return HTMINBUTTON;
301 298
302 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate(); 299 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate();
303 if (delegate == NULL) { 300 if (delegate == NULL) {
304 LOG(INFO) << "delegate is NULL, returning safe default."; 301 LOG(WARNING) << "delegate is NULL, returning safe default.";
305 return HTNOWHERE; 302 return HTCAPTION;
306 } 303 }
307 int window_component = GetHTComponentForFrame(point, TopResizeHeight(), 304 int window_component = GetHTComponentForFrame(point, TopResizeHeight(),
308 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, 305 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize,
309 delegate->CanResize()); 306 delegate->CanResize());
310 // Fall back to the caption if no other component matches. 307 // Fall back to the caption if no other component matches.
311 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; 308 return (window_component == HTNOWHERE) ? HTCAPTION : window_component;
312 } 309 }
313 310
314 void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size, 311 void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size,
315 gfx::Path* window_mask) { 312 gfx::Path* window_mask) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 // This function is queried during the creation of the window as the 410 // This function is queried during the creation of the window as the
414 // TabIconView we host is initialized, so we need to NULL check the selected 411 // TabIconView we host is initialized, so we need to NULL check the selected
415 // TabContents because in this condition there is not yet a selected tab. 412 // TabContents because in this condition there is not yet a selected tab.
416 TabContents* current_tab = browser_view_->GetSelectedTabContents(); 413 TabContents* current_tab = browser_view_->GetSelectedTabContents();
417 return current_tab ? current_tab->is_loading() : false; 414 return current_tab ? current_tab->is_loading() : false;
418 } 415 }
419 416
420 SkBitmap OpaqueBrowserFrameView::GetFavIconForTabIconView() { 417 SkBitmap OpaqueBrowserFrameView::GetFavIconForTabIconView() {
421 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate(); 418 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate();
422 if (delegate == NULL) { 419 if (delegate == NULL) {
423 LOG(INFO) << "delegate is NULL, returning safe default."; 420 LOG(WARNING) << "delegate is NULL, returning safe default.";
424 return SkBitmap(); 421 return SkBitmap();
425 } 422 }
426 return delegate->GetWindowIcon(); 423 return delegate->GetWindowIcon();
427 } 424 }
428 425
429 /////////////////////////////////////////////////////////////////////////////// 426 ///////////////////////////////////////////////////////////////////////////////
430 // OpaqueBrowserFrameView, private: 427 // OpaqueBrowserFrameView, private:
431 428
432 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const { 429 int OpaqueBrowserFrameView::FrameBorderThickness(bool restored) const {
433 views::Window* window = frame_->GetWindow(); 430 views::Window* window = frame_->GetWindow();
(...skipping 11 matching lines...) Expand all
445 return FrameBorderThickness(false) + 442 return FrameBorderThickness(false) +
446 ((window->IsMaximized() || window->IsFullscreen()) ? 443 ((window->IsMaximized() || window->IsFullscreen()) ?
447 0 : kClientEdgeThickness); 444 0 : kClientEdgeThickness);
448 } 445 }
449 446
450 int OpaqueBrowserFrameView::NonClientTopBorderHeight( 447 int OpaqueBrowserFrameView::NonClientTopBorderHeight(
451 bool restored, 448 bool restored,
452 bool ignore_vertical_tabs) const { 449 bool ignore_vertical_tabs) const {
453 views::Window* window = frame_->GetWindow(); 450 views::Window* window = frame_->GetWindow();
454 views::WindowDelegate* delegate = window->GetDelegate(); 451 views::WindowDelegate* delegate = window->GetDelegate();
455 // |delegate| may be NULL if called from callback of InputMethodChanged 452 // |delegate| may be NULL if called from callback of InputMethodChanged while
456 // while a window is being destroyed. 453 // a window is being destroyed.
457 // See more discussion at http://crosbug.com/8958 454 // See more discussion at http://crosbug.com/8958
458 if (!delegate) { 455 if ((delegate && delegate->ShouldShowWindowTitle()) ||
459 LOG(INFO) << "delegate is NULL";
460 return 0;
461 }
462
463 if (delegate->ShouldShowWindowTitle() ||
464 (browser_view_->IsTabStripVisible() && !ignore_vertical_tabs && 456 (browser_view_->IsTabStripVisible() && !ignore_vertical_tabs &&
465 browser_view_->UseVerticalTabs())) { 457 browser_view_->UseVerticalTabs())) {
466 return std::max(FrameBorderThickness(restored) + IconSize(), 458 return std::max(FrameBorderThickness(restored) + IconSize(),
467 CaptionButtonY(restored) + kCaptionButtonHeightWithPadding) + 459 CaptionButtonY(restored) + kCaptionButtonHeightWithPadding) +
468 TitlebarBottomThickness(restored); 460 TitlebarBottomThickness(restored);
469 } 461 }
470 462
471 return FrameBorderThickness(restored) - 463 return FrameBorderThickness(restored) -
472 ((browser_view_->IsTabStripVisible() && !restored && 464 ((browser_view_->IsTabStripVisible() && !restored &&
473 window->IsMaximized()) ? kTabstripTopShadowThickness : 0); 465 window->IsMaximized()) ? kTabstripTopShadowThickness : 0);
474 } 466 }
475 467
(...skipping 18 matching lines...) Expand all
494 #else 486 #else
495 return std::max(BrowserFrame::GetTitleFont().GetHeight(), kIconMinimumSize); 487 return std::max(BrowserFrame::GetTitleFont().GetHeight(), kIconMinimumSize);
496 #endif 488 #endif
497 } 489 }
498 490
499 gfx::Rect OpaqueBrowserFrameView::IconBounds() const { 491 gfx::Rect OpaqueBrowserFrameView::IconBounds() const {
500 int size = IconSize(); 492 int size = IconSize();
501 int frame_thickness = FrameBorderThickness(false); 493 int frame_thickness = FrameBorderThickness(false);
502 int y; 494 int y;
503 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate(); 495 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate();
504 if (delegate == NULL) { 496 if (delegate && (delegate->ShouldShowWindowIcon() ||
505 LOG(INFO) << "delegate is NULL, returning safe default."; 497 delegate->ShouldShowWindowTitle())) {
506 return gfx::Rect(0, 0, 0, 0);
507 }
508 if (delegate->ShouldShowWindowIcon() || delegate->ShouldShowWindowTitle()) {
509 // Our frame border has a different "3D look" than Windows'. Theirs has a 498 // Our frame border has a different "3D look" than Windows'. Theirs has a
510 // more complex gradient on the top that they push their icon/title below; 499 // more complex gradient on the top that they push their icon/title below;
511 // then the maximized window cuts this off and the icon/title are centered 500 // then the maximized window cuts this off and the icon/title are centered
512 // in the remaining space. Because the apparent shape of our border is 501 // in the remaining space. Because the apparent shape of our border is
513 // simpler, using the same positioning makes things look slightly uncentered 502 // simpler, using the same positioning makes things look slightly uncentered
514 // with restored windows, so when the window is restored, instead of 503 // with restored windows, so when the window is restored, instead of
515 // calculating the remaining space from below the frame border, we calculate 504 // calculating the remaining space from below the frame border, we calculate
516 // from below the 3D edge. 505 // from below the 3D edge.
517 int unavailable_px_at_top = frame_->GetWindow()->IsMaximized() ? 506 int unavailable_px_at_top = frame_->GetWindow()->IsMaximized() ?
518 frame_thickness : kTitlebarTopAndBottomEdgeThickness; 507 frame_thickness : kTitlebarTopAndBottomEdgeThickness;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 int edge_height = top_center->height() - kClientEdgeThickness; 682 int edge_height = top_center->height() - kClientEdgeThickness;
694 canvas->TileImageInt(*top_center, 0, 683 canvas->TileImageInt(*top_center, 0,
695 window->GetClientView()->y() - edge_height, width(), edge_height); 684 window->GetClientView()->y() - edge_height, width(), edge_height);
696 } 685 }
697 } 686 }
698 687
699 void OpaqueBrowserFrameView::PaintTitleBar(gfx::Canvas* canvas) { 688 void OpaqueBrowserFrameView::PaintTitleBar(gfx::Canvas* canvas) {
700 // The window icon is painted by the TabIconView. 689 // The window icon is painted by the TabIconView.
701 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate(); 690 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate();
702 if (delegate == NULL) { 691 if (delegate == NULL) {
703 LOG(INFO) << "delegate is NULL"; 692 LOG(WARNING) << "delegate is NULL";
704 return; 693 return;
705 } 694 }
706 if (delegate->ShouldShowWindowTitle()) { 695 if (delegate->ShouldShowWindowTitle()) {
707 canvas->DrawStringInt(delegate->GetWindowTitle(), 696 canvas->DrawStringInt(delegate->GetWindowTitle(),
708 BrowserFrame::GetTitleFont(), 697 BrowserFrame::GetTitleFont(),
709 SK_ColorWHITE, MirroredLeftPointForRect(title_bounds_), 698 SK_ColorWHITE, MirroredLeftPointForRect(title_bounds_),
710 title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); 699 title_bounds_.y(), title_bounds_.width(), title_bounds_.height());
711 /* TODO(pkasting): If this window is active, we should also draw a drop 700 /* TODO(pkasting): If this window is active, we should also draw a drop
712 * shadow on the title. This is tricky, because we don't want to hardcode a 701 * shadow on the title. This is tricky, because we don't want to hardcode a
713 * shadow color (since we want to work with various themes), but we can't 702 * shadow color (since we want to work with various themes), but we can't
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 visible_button->x() - minimize_button_size.width(), caption_y, 996 visible_button->x() - minimize_button_size.width(), caption_y,
1008 minimize_button_size.width(), 997 minimize_button_size.width(),
1009 minimize_button_size.height()); 998 minimize_button_size.height());
1010 } 999 }
1011 1000
1012 void OpaqueBrowserFrameView::LayoutTitleBar() { 1001 void OpaqueBrowserFrameView::LayoutTitleBar() {
1013 // The window title is based on the calculated icon position, even when there 1002 // The window title is based on the calculated icon position, even when there
1014 // is no icon. 1003 // is no icon.
1015 gfx::Rect icon_bounds(IconBounds()); 1004 gfx::Rect icon_bounds(IconBounds());
1016 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate(); 1005 views::WindowDelegate* delegate = frame_->GetWindow()->GetDelegate();
1017 if (delegate == NULL) { 1006 if (delegate && delegate->ShouldShowWindowIcon())
1018 LOG(INFO) << "delegate is NULL";
1019 return;
1020 }
1021 if (delegate->ShouldShowWindowIcon())
1022 window_icon_->SetBounds(icon_bounds); 1007 window_icon_->SetBounds(icon_bounds);
1023 1008
1024 // Size the title, if visible. 1009 // Size the title, if visible.
1025 if (delegate->ShouldShowWindowTitle()) { 1010 if (delegate && delegate->ShouldShowWindowTitle()) {
1026 int title_x = delegate->ShouldShowWindowIcon() ? 1011 int title_x = delegate->ShouldShowWindowIcon() ?
1027 icon_bounds.right() + kIconTitleSpacing : icon_bounds.x(); 1012 icon_bounds.right() + kIconTitleSpacing : icon_bounds.x();
1028 int title_height = BrowserFrame::GetTitleFont().GetHeight(); 1013 int title_height = BrowserFrame::GetTitleFont().GetHeight();
1029 // We bias the title position so that when the difference between the icon 1014 // We bias the title position so that when the difference between the icon
1030 // and title heights is odd, the extra pixel of the title is above the 1015 // and title heights is odd, the extra pixel of the title is above the
1031 // vertical midline rather than below. This compensates for how the icon is 1016 // vertical midline rather than below. This compensates for how the icon is
1032 // already biased downwards (see IconBounds()) and helps prevent descenders 1017 // already biased downwards (see IconBounds()) and helps prevent descenders
1033 // on the title from overlapping the 3D edge at the bottom of the titlebar. 1018 // on the title from overlapping the 3D edge at the bottom of the titlebar.
1034 title_bounds_.SetRect(title_x, 1019 title_bounds_.SetRect(title_x,
1035 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2), 1020 icon_bounds.y() + ((icon_bounds.height() - title_height - 1) / 2),
(...skipping 22 matching lines...) Expand all
1058 } 1043 }
1059 1044
1060 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width, 1045 gfx::Rect OpaqueBrowserFrameView::CalculateClientAreaBounds(int width,
1061 int height) const { 1046 int height) const {
1062 int top_height = NonClientTopBorderHeight(false, false); 1047 int top_height = NonClientTopBorderHeight(false, false);
1063 int border_thickness = NonClientBorderThickness(); 1048 int border_thickness = NonClientBorderThickness();
1064 return gfx::Rect(border_thickness, top_height, 1049 return gfx::Rect(border_thickness, top_height,
1065 std::max(0, width - (2 * border_thickness)), 1050 std::max(0, width - (2 * border_thickness)),
1066 std::max(0, height - top_height - border_thickness)); 1051 std::max(0, height - top_height - border_thickness));
1067 } 1052 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698