Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ui/views/frame/browser_non_client_frame_view_ash.h" | 5 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" | 8 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
| 9 #include "ash/wm/frame_border_hit_test_controller.h" | 9 #include "ash/wm/frame_border_hit_test_controller.h" |
| 10 #include "ash/wm/header_painter.h" | 10 #include "ash/wm/header_painter.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 | 149 |
| 150 void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) { | 150 void BrowserNonClientFrameViewAsh::UpdateThrobber(bool running) { |
| 151 if (window_icon_) | 151 if (window_icon_) |
| 152 window_icon_->Update(); | 152 window_icon_->Update(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 /////////////////////////////////////////////////////////////////////////////// | 155 /////////////////////////////////////////////////////////////////////////////// |
| 156 // views::NonClientFrameView overrides: | 156 // views::NonClientFrameView overrides: |
| 157 | 157 |
| 158 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForClientView() const { | 158 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForClientView() const { |
| 159 int top_height = NonClientTopBorderHeight(); | 159 // The ClientView must be flush with the top edge of the widget so that the |
| 160 return ash::HeaderPainter::GetBoundsForClientView(top_height, bounds()); | 160 // web contents can take up the entire screen in immersive fullscreen (with |
| 161 // or without the top-of-window views revealed) When in immersive fullscreen | |
|
James Cook
2013/11/25 19:09:20
nit. Missing . after )
| |
| 162 // and the top-of-window views are revealed, the TopContainerView paints the | |
| 163 // window header by redirecting paints from its background to | |
| 164 // BrowserNonClientFrameViewAsh. | |
| 165 return ash::HeaderPainter::GetBoundsForClientView(0, bounds()); | |
| 161 } | 166 } |
| 162 | 167 |
| 163 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds( | 168 gfx::Rect BrowserNonClientFrameViewAsh::GetWindowBoundsForClientBounds( |
| 164 const gfx::Rect& client_bounds) const { | 169 const gfx::Rect& client_bounds) const { |
| 165 int top_height = NonClientTopBorderHeight(); | 170 return ash::HeaderPainter::GetWindowBoundsForClientBounds(0, client_bounds); |
| 166 return ash::HeaderPainter::GetWindowBoundsForClientBounds(top_height, | |
| 167 client_bounds); | |
| 168 } | 171 } |
| 169 | 172 |
| 170 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) { | 173 int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) { |
| 171 int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this, | 174 int hit_test = ash::FrameBorderHitTestController::NonClientHitTest(this, |
| 172 header_painter_.get(), point); | 175 header_painter_.get(), point); |
| 173 | 176 |
| 174 // See if the point is actually within the avatar menu button or within | 177 // See if the point is actually within the avatar menu button or within |
| 175 // the avatar label. | 178 // the avatar label. |
| 176 if (hit_test == HTCAPTION && ((avatar_button() && | 179 if (hit_test == HTCAPTION && ((avatar_button() && |
| 177 avatar_button()->GetMirroredBounds().Contains(point)) || | 180 avatar_button()->GetMirroredBounds().Contains(point)) || |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 theme_frame_overlay_image_id); | 257 theme_frame_overlay_image_id); |
| 255 if (browser_view()->ShouldShowWindowTitle()) | 258 if (browser_view()->ShouldShowWindowTitle()) |
| 256 header_painter_->PaintTitleBar(canvas, BrowserFrame::GetTitleFont()); | 259 header_painter_->PaintTitleBar(canvas, BrowserFrame::GetTitleFont()); |
| 257 if (browser_view()->IsToolbarVisible()) | 260 if (browser_view()->IsToolbarVisible()) |
| 258 PaintToolbarBackground(canvas); | 261 PaintToolbarBackground(canvas); |
| 259 else | 262 else |
| 260 PaintContentEdge(canvas); | 263 PaintContentEdge(canvas); |
| 261 } | 264 } |
| 262 | 265 |
| 263 void BrowserNonClientFrameViewAsh::Layout() { | 266 void BrowserNonClientFrameViewAsh::Layout() { |
| 264 header_painter_->LayoutHeader(UseShortHeader()); | |
| 265 int header_height = 0; | 267 int header_height = 0; |
| 266 if (browser_view()->IsTabStripVisible()) { | 268 if (browser_view()->IsTabStripVisible()) { |
| 267 header_height = GetTopInset() + | 269 header_height = GetTopInset() + |
| 268 browser_view()->GetTabStripHeight(); | 270 browser_view()->GetTabStripHeight(); |
| 269 } else if (browser_view()->IsToolbarVisible()) { | 271 } else if (browser_view()->IsToolbarVisible()) { |
| 270 // Set the header's height so that it overlaps with the toolbar because the | 272 // Set the header's height so that it overlaps with the toolbar because the |
| 271 // top few pixels of the toolbar are not opaque. | 273 // top few pixels of the toolbar are not opaque. |
| 272 gfx::Point toolbar_origin(browser_view()->GetToolbarBounds().origin()); | 274 header_height = GetTopInset() + kFrameShadowThickness * 2; |
|
pkotwicz
2013/11/23 21:37:15
This code is wrong. BrowserNonClientFrameViewAsh::
| |
| 273 View::ConvertPointToTarget(browser_view(), this, &toolbar_origin); | |
| 274 header_height = toolbar_origin.y() + kFrameShadowThickness * 2; | |
| 275 } else { | 275 } else { |
| 276 header_height = NonClientTopBorderHeight(); | 276 header_height = GetTopInset(); |
| 277 } | 277 } |
| 278 header_painter_->set_header_height(header_height); | 278 header_painter_->set_header_height(header_height); |
| 279 header_painter_->LayoutHeader(UseShortHeader()); | |
| 279 if (avatar_button()) | 280 if (avatar_button()) |
| 280 LayoutAvatar(); | 281 LayoutAvatar(); |
| 281 BrowserNonClientFrameView::Layout(); | 282 BrowserNonClientFrameView::Layout(); |
| 282 } | 283 } |
| 283 | 284 |
| 284 const char* BrowserNonClientFrameViewAsh::GetClassName() const { | 285 const char* BrowserNonClientFrameViewAsh::GetClassName() const { |
| 285 return kViewClassName; | 286 return kViewClassName; |
| 286 } | 287 } |
| 287 | 288 |
| 288 bool BrowserNonClientFrameViewAsh::HitTestRect(const gfx::Rect& rect) const { | 289 bool BrowserNonClientFrameViewAsh::HitTestRect(const gfx::Rect& rect) const { |
| 289 if (!views::View::HitTestRect(rect)) { | 290 if (!views::View::HitTestRect(rect)) { |
| 290 // |rect| is outside BrowserNonClientFrameViewAsh's bounds. | 291 // |rect| is outside BrowserNonClientFrameViewAsh's bounds. |
| 291 return false; | 292 return false; |
| 292 } | 293 } |
| 293 // If the rect is outside the bounds of the client area, claim it. | |
| 294 gfx::RectF rect_in_client_view_coords_f(rect); | |
| 295 View::ConvertRectToTarget(this, frame()->client_view(), | |
| 296 &rect_in_client_view_coords_f); | |
| 297 gfx::Rect rect_in_client_view_coords = gfx::ToEnclosingRect( | |
| 298 rect_in_client_view_coords_f); | |
| 299 if (!frame()->client_view()->HitTestRect(rect_in_client_view_coords)) | |
| 300 return true; | |
| 301 | 294 |
| 302 // Otherwise, claim |rect| only if it is above the bottom of the tabstrip in | |
| 303 // a non-tab portion. | |
| 304 TabStrip* tabstrip = browser_view()->tabstrip(); | 295 TabStrip* tabstrip = browser_view()->tabstrip(); |
| 305 if (!tabstrip || !browser_view()->IsTabStripVisible()) | 296 if (tabstrip && browser_view()->IsTabStripVisible()) { |
| 306 return false; | 297 // Claim |rect| only if it is above the bottom of the tabstrip in a non-tab |
| 298 // portion. | |
| 299 gfx::RectF rect_in_tabstrip_coords_f(rect); | |
| 300 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f); | |
| 301 gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect( | |
| 302 rect_in_tabstrip_coords_f); | |
| 307 | 303 |
| 308 gfx::RectF rect_in_tabstrip_coords_f(rect); | 304 if (rect_in_tabstrip_coords.y() > tabstrip->height()) |
| 309 View::ConvertRectToTarget(this, tabstrip, &rect_in_tabstrip_coords_f); | 305 return false; |
| 310 gfx::Rect rect_in_tabstrip_coords = gfx::ToEnclosingRect( | |
| 311 rect_in_tabstrip_coords_f); | |
| 312 | 306 |
| 313 if (rect_in_tabstrip_coords.y() > tabstrip->GetLocalBounds().bottom()) { | 307 return !tabstrip->HitTestRect(rect_in_tabstrip_coords) || |
| 314 // |rect| is below the tabstrip. | 308 tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords); |
| 315 return false; | |
| 316 } | 309 } |
| 317 | 310 |
| 318 if (tabstrip->HitTestRect(rect_in_tabstrip_coords)) { | 311 // Claim |rect| if it is above the top of the topmost view in the client area. |
| 319 // Claim |rect| if it is in a non-tab portion of the tabstrip. | 312 return (rect.y() < GetTopInset()); |
|
James Cook
2013/11/25 19:09:20
nit: no need for extra parens
| |
| 320 return tabstrip->IsRectInWindowCaption(rect_in_tabstrip_coords); | |
| 321 } | |
| 322 | |
| 323 // We claim |rect| because it is above the bottom of the tabstrip, but | |
| 324 // not in the tabstrip. In particular, the window controls are right of | |
| 325 // the tabstrip. | |
| 326 return true; | |
| 327 } | 313 } |
| 328 | 314 |
| 329 void BrowserNonClientFrameViewAsh::GetAccessibleState( | 315 void BrowserNonClientFrameViewAsh::GetAccessibleState( |
| 330 ui::AccessibleViewState* state) { | 316 ui::AccessibleViewState* state) { |
| 331 state->role = ui::AccessibilityTypes::ROLE_TITLEBAR; | 317 state->role = ui::AccessibilityTypes::ROLE_TITLEBAR; |
| 332 } | 318 } |
| 333 | 319 |
| 334 gfx::Size BrowserNonClientFrameViewAsh::GetMinimumSize() { | 320 gfx::Size BrowserNonClientFrameViewAsh::GetMinimumSize() { |
| 335 gfx::Size min_client_view_size(frame()->client_view()->GetMinimumSize()); | 321 gfx::Size min_client_view_size(frame()->client_view()->GetMinimumSize()); |
| 336 return gfx::Size( | 322 return gfx::Size( |
| 337 std::max(header_painter_->GetMinimumHeaderWidth(), | 323 std::max(header_painter_->GetMinimumHeaderWidth(), |
| 338 min_client_view_size.width()), | 324 min_client_view_size.width()), |
| 339 NonClientTopBorderHeight() + min_client_view_size.height()); | 325 min_client_view_size.height()); |
| 340 } | 326 } |
| 341 | 327 |
| 342 void BrowserNonClientFrameViewAsh::OnThemeChanged() { | 328 void BrowserNonClientFrameViewAsh::OnThemeChanged() { |
| 343 BrowserNonClientFrameView::OnThemeChanged(); | 329 BrowserNonClientFrameView::OnThemeChanged(); |
| 344 header_painter_->OnThemeChanged(); | 330 header_painter_->OnThemeChanged(); |
| 345 } | 331 } |
| 346 | 332 |
| 347 /////////////////////////////////////////////////////////////////////////////// | 333 /////////////////////////////////////////////////////////////////////////////// |
| 348 // chrome::TabIconViewModel overrides: | 334 // chrome::TabIconViewModel overrides: |
| 349 | 335 |
| 350 bool BrowserNonClientFrameViewAsh::ShouldTabIconViewAnimate() const { | 336 bool BrowserNonClientFrameViewAsh::ShouldTabIconViewAnimate() const { |
| 351 // This function is queried during the creation of the window as the | 337 // This function is queried during the creation of the window as the |
| 352 // TabIconView we host is initialized, so we need to NULL check the selected | 338 // TabIconView we host is initialized, so we need to NULL check the selected |
| 353 // WebContents because in this condition there is not yet a selected tab. | 339 // WebContents because in this condition there is not yet a selected tab. |
| 354 content::WebContents* current_tab = browser_view()->GetActiveWebContents(); | 340 content::WebContents* current_tab = browser_view()->GetActiveWebContents(); |
| 355 return current_tab ? current_tab->IsLoading() : false; | 341 return current_tab ? current_tab->IsLoading() : false; |
| 356 } | 342 } |
| 357 | 343 |
| 358 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { | 344 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { |
| 359 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 345 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
| 360 if (!delegate) | 346 if (!delegate) |
| 361 return gfx::ImageSkia(); | 347 return gfx::ImageSkia(); |
| 362 return delegate->GetWindowIcon(); | 348 return delegate->GetWindowIcon(); |
| 363 } | 349 } |
| 364 | 350 |
| 365 /////////////////////////////////////////////////////////////////////////////// | 351 /////////////////////////////////////////////////////////////////////////////// |
| 366 // BrowserNonClientFrameViewAsh, private: | 352 // BrowserNonClientFrameViewAsh, private: |
| 367 | 353 |
| 368 int BrowserNonClientFrameViewAsh::NonClientTopBorderHeight() const { | |
| 369 if (!ShouldPaint() || browser_view()->IsTabStripVisible()) | |
| 370 return 0; | |
| 371 | |
| 372 int caption_buttons_bottom = caption_button_container_->bounds().bottom(); | |
| 373 if (browser_view()->IsToolbarVisible()) | |
| 374 return caption_buttons_bottom - kContentShadowHeight; | |
| 375 return caption_buttons_bottom + kClientEdgeThickness; | |
| 376 } | |
| 377 | |
| 378 bool BrowserNonClientFrameViewAsh::UseShortHeader() const { | 354 bool BrowserNonClientFrameViewAsh::UseShortHeader() const { |
| 379 // Restored tabbed browser windows use the tall header. All other windows use | 355 // Restored tabbed browser windows use the tall header. All other windows use |
| 380 // the short header. | 356 // the short header. |
| 381 return frame()->IsMaximized() || | 357 return frame()->IsMaximized() || |
| 382 frame()->IsFullscreen() || | 358 frame()->IsFullscreen() || |
| 383 !browser_view()->IsBrowserTypeNormal(); | 359 !browser_view()->IsBrowserTypeNormal(); |
| 384 } | 360 } |
| 385 | 361 |
| 386 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { | 362 bool BrowserNonClientFrameViewAsh::UseImmersiveLightbarHeaderStyle() const { |
| 387 ImmersiveModeController* immersive_controller = | 363 ImmersiveModeController* immersive_controller = |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 416 avatar_button()->SetVisible(avatar_visible); | 392 avatar_button()->SetVisible(avatar_visible); |
| 417 } | 393 } |
| 418 | 394 |
| 419 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { | 395 bool BrowserNonClientFrameViewAsh::ShouldPaint() const { |
| 420 if (!frame()->IsFullscreen()) | 396 if (!frame()->IsFullscreen()) |
| 421 return true; | 397 return true; |
| 422 | 398 |
| 423 // We need to paint when in immersive fullscreen and either: | 399 // We need to paint when in immersive fullscreen and either: |
| 424 // - The top-of-window views are revealed. | 400 // - The top-of-window views are revealed. |
| 425 // - The lightbar style tabstrip is visible. | 401 // - The lightbar style tabstrip is visible. |
| 426 // Because immersive fullscreen is only supported for tabbed browser windows, | 402 ImmersiveModeController* immersive_mode_controller = |
| 427 // checking whether the tab strip is visible is sufficient. | 403 browser_view()->immersive_mode_controller(); |
| 428 return browser_view()->IsTabStripVisible(); | 404 return immersive_mode_controller->IsEnabled() && |
| 405 (immersive_mode_controller->IsRevealed() || | |
| 406 UseImmersiveLightbarHeaderStyle()); | |
| 429 } | 407 } |
| 430 | 408 |
| 431 void BrowserNonClientFrameViewAsh::PaintImmersiveLightbarStyleHeader( | 409 void BrowserNonClientFrameViewAsh::PaintImmersiveLightbarStyleHeader( |
| 432 gfx::Canvas* canvas) { | 410 gfx::Canvas* canvas) { |
| 433 // The light bar header is not themed because theming it does not look good. | 411 // The light bar header is not themed because theming it does not look good. |
| 434 gfx::ImageSkia* frame_image = GetThemeProvider()->GetImageSkiaNamed( | 412 gfx::ImageSkia* frame_image = GetThemeProvider()->GetImageSkiaNamed( |
| 435 IDR_AURA_WINDOW_HEADER_BASE_MINIMAL); | 413 IDR_AURA_WINDOW_HEADER_BASE_MINIMAL); |
| 436 canvas->TileImageInt(*frame_image, 0, 0, width(), frame_image->height()); | 414 canvas->TileImageInt(*frame_image, 0, 0, width(), frame_image->height()); |
| 437 } | 415 } |
| 438 | 416 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 int BrowserNonClientFrameViewAsh::GetThemeFrameOverlayImageId() const { | 520 int BrowserNonClientFrameViewAsh::GetThemeFrameOverlayImageId() const { |
| 543 ui::ThemeProvider* tp = GetThemeProvider(); | 521 ui::ThemeProvider* tp = GetThemeProvider(); |
| 544 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && | 522 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && |
| 545 browser_view()->IsBrowserTypeNormal() && | 523 browser_view()->IsBrowserTypeNormal() && |
| 546 !browser_view()->IsOffTheRecord()) { | 524 !browser_view()->IsOffTheRecord()) { |
| 547 return ShouldPaintAsActive() ? | 525 return ShouldPaintAsActive() ? |
| 548 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE; | 526 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE; |
| 549 } | 527 } |
| 550 return 0; | 528 return 0; |
| 551 } | 529 } |
| OLD | NEW |