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/ash/browser_non_client_frame_view_ash.h" | 5 #include "chrome/browser/ui/views/ash/browser_non_client_frame_view_ash.h" |
6 | 6 |
7 #include "ash/wm/frame_painter.h" | 7 #include "ash/wm/frame_painter.h" |
8 #include "ash/wm/workspace/frame_maximize_button.h" | 8 #include "ash/wm/workspace/frame_maximize_button.h" |
9 #include "chrome/browser/themes/theme_service.h" | 9 #include "chrome/browser/themes/theme_service.h" |
10 #include "chrome/browser/ui/browser.h" | |
11 #include "chrome/browser/ui/search/search.h" | |
12 #include "chrome/browser/ui/search/search_delegate.h" | |
13 #include "chrome/browser/ui/search/search_model.h" | |
10 #include "chrome/browser/ui/views/avatar_menu_button.h" | 14 #include "chrome/browser/ui/views/avatar_menu_button.h" |
11 #include "chrome/browser/ui/views/frame/browser_frame.h" | 15 #include "chrome/browser/ui/views/frame/browser_frame.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
13 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 17 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
18 #include "chrome/browser/ui/views/toolbar_view.h" | |
14 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
15 #include "grit/generated_resources.h" // Accessibility names | 20 #include "grit/generated_resources.h" // Accessibility names |
16 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
17 #include "grit/theme_resources_standard.h" | 22 #include "grit/theme_resources_standard.h" |
18 #include "grit/ui_resources.h" | 23 #include "grit/ui_resources.h" |
19 #include "ui/aura/client/aura_constants.h" | 24 #include "ui/aura/client/aura_constants.h" |
20 #include "ui/aura/window.h" | 25 #include "ui/aura/window.h" |
21 #include "ui/base/accessibility/accessible_view_state.h" | 26 #include "ui/base/accessibility/accessible_view_state.h" |
22 #include "ui/base/hit_test.h" | 27 #include "ui/base/hit_test.h" |
23 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 BrowserFrame* frame, BrowserView* browser_view) | 128 BrowserFrame* frame, BrowserView* browser_view) |
124 : BrowserNonClientFrameView(frame, browser_view), | 129 : BrowserNonClientFrameView(frame, browser_view), |
125 size_button_(NULL), | 130 size_button_(NULL), |
126 close_button_(NULL), | 131 close_button_(NULL), |
127 window_icon_(NULL), | 132 window_icon_(NULL), |
128 frame_painter_(new ash::FramePainter), | 133 frame_painter_(new ash::FramePainter), |
129 size_button_minimizes_(false) { | 134 size_button_minimizes_(false) { |
130 } | 135 } |
131 | 136 |
132 BrowserNonClientFrameViewAsh::~BrowserNonClientFrameViewAsh() { | 137 BrowserNonClientFrameViewAsh::~BrowserNonClientFrameViewAsh() { |
138 // A non-NULL |size_button_| means it was initialized in Init() where | |
139 // |this| was added as observer to ToolbarSearchAnimator, so remove it now. | |
140 if (size_button_) { | |
141 browser_view()->browser()->search_delegate()->toolbar_search_animator(). | |
142 RemoveObserver(this); | |
143 } | |
133 } | 144 } |
134 | 145 |
135 void BrowserNonClientFrameViewAsh::Init() { | 146 void BrowserNonClientFrameViewAsh::Init() { |
136 // Panels only minimize. | 147 // Panels only minimize. |
137 ash::FramePainter::SizeButtonBehavior size_button_behavior; | 148 ash::FramePainter::SizeButtonBehavior size_button_behavior; |
138 if (browser_view()->browser()->is_type_panel() && | 149 if (browser_view()->browser()->is_type_panel() && |
139 browser_view()->browser()->app_type() == Browser::APP_TYPE_CHILD) { | 150 browser_view()->browser()->app_type() == Browser::APP_TYPE_CHILD) { |
140 size_button_minimizes_ = true; | 151 size_button_minimizes_ = true; |
141 size_button_ = new views::ImageButton(this); | 152 size_button_ = new views::ImageButton(this); |
142 size_button_behavior = ash::FramePainter::SIZE_BUTTON_MINIMIZES; | 153 size_button_behavior = ash::FramePainter::SIZE_BUTTON_MINIMIZES; |
(...skipping 16 matching lines...) Expand all Loading... | |
159 AddChildView(window_icon_); | 170 AddChildView(window_icon_); |
160 window_icon_->Update(); | 171 window_icon_->Update(); |
161 } | 172 } |
162 | 173 |
163 // Create incognito icon if necessary. | 174 // Create incognito icon if necessary. |
164 UpdateAvatarInfo(); | 175 UpdateAvatarInfo(); |
165 | 176 |
166 // Frame painter handles layout of these buttons. | 177 // Frame painter handles layout of these buttons. |
167 frame_painter_->Init(frame(), window_icon_, size_button_, close_button_, | 178 frame_painter_->Init(frame(), window_icon_, size_button_, close_button_, |
168 size_button_behavior); | 179 size_button_behavior); |
180 | |
181 browser_view()->browser()->search_delegate()->toolbar_search_animator(). | |
182 AddObserver(this); | |
169 } | 183 } |
170 | 184 |
171 /////////////////////////////////////////////////////////////////////////////// | 185 /////////////////////////////////////////////////////////////////////////////// |
172 // BrowserNonClientFrameView overrides: | 186 // BrowserNonClientFrameView overrides: |
173 | 187 |
174 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForTabStrip( | 188 gfx::Rect BrowserNonClientFrameViewAsh::GetBoundsForTabStrip( |
175 views::View* tabstrip) const { | 189 views::View* tabstrip) const { |
176 if (!tabstrip) | 190 if (!tabstrip) |
177 return gfx::Rect(); | 191 return gfx::Rect(); |
178 int tabstrip_x = | 192 int tabstrip_x = |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 // theme, so we look it up for each paint. | 267 // theme, so we look it up for each paint. |
254 frame_painter_->PaintHeader( | 268 frame_painter_->PaintHeader( |
255 this, | 269 this, |
256 canvas, | 270 canvas, |
257 ShouldPaintAsActive() ? | 271 ShouldPaintAsActive() ? |
258 ash::FramePainter::ACTIVE : ash::FramePainter::INACTIVE, | 272 ash::FramePainter::ACTIVE : ash::FramePainter::INACTIVE, |
259 GetThemeFrameImageId(), | 273 GetThemeFrameImageId(), |
260 GetThemeFrameOverlayImage()); | 274 GetThemeFrameOverlayImage()); |
261 if (browser_view()->ShouldShowWindowTitle()) | 275 if (browser_view()->ShouldShowWindowTitle()) |
262 frame_painter_->PaintTitleBar(this, canvas, BrowserFrame::GetTitleFont()); | 276 frame_painter_->PaintTitleBar(this, canvas, BrowserFrame::GetTitleFont()); |
263 if (browser_view()->IsToolbarVisible()) | 277 if (browser_view()->IsToolbarVisible()) { |
264 PaintToolbarBackground(canvas); | 278 chrome::search::Mode mode = |
sky
2012/06/26 17:11:27
I tend to think this code makes more sense in Pain
kuan
2012/06/26 23:25:49
if i move this code to PaintToolbarBackground, how
sky
2012/06/27 00:06:17
Good point. Leave it then.
| |
265 else | 279 browser_view()->browser()->search_model()->mode(); |
280 bool fading_in = false; | |
281 // If mode is SEARCH, we might be waiting to fade in or fading in new | |
sky
2012/06/26 17:11:27
Update comment.
kuan
2012/06/26 23:25:49
Done.
| |
282 // background, in which case, the previous background needs to be painted. | |
283 if (mode.is_search()) { | |
284 // Get current state of background animation to paint for SEARCH mode. | |
sky
2012/06/26 17:11:27
Fold this into a better comment on 281.
kuan
2012/06/26 23:25:49
Done.
| |
285 chrome::search::ToolbarSearchAnimator::BackgroundState background_state = | |
286 chrome::search::ToolbarSearchAnimator:: | |
287 BACKGROUND_STATE_SHOW_NON_APPLICABLE; | |
288 int new_background_opacity = -1; | |
289 browser_view()->browser()->search_delegate()->toolbar_search_animator(). | |
290 GetCurrentBackgroundState(&background_state, &new_background_opacity); | |
291 if (background_state & | |
292 chrome::search::ToolbarSearchAnimator::BACKGROUND_STATE_SHOW_NTP) { | |
293 // Paint background for NTP mode. | |
294 PaintToolbarBackground(canvas, chrome::search::Mode::MODE_NTP); | |
295 // We're done if we're not showing background for SEARCH mode. | |
296 if (!(background_state & chrome::search::ToolbarSearchAnimator:: | |
297 BACKGROUND_STATE_SHOW_SEARCH)) { | |
298 return; | |
299 } | |
300 // Otherwise, we're fading in the new background at | |
301 // |new_background_opacity|. | |
302 fading_in = true; | |
303 canvas->SaveLayerAlpha(static_cast<uint8>(new_background_opacity)); | |
304 } | |
305 } | |
306 // Paint the background for the current mode. | |
307 PaintToolbarBackground(canvas, mode.mode); | |
308 // If we're fading in and have saved canvas, restore it now. | |
309 if (fading_in) | |
310 canvas->Restore(); | |
311 } else { | |
266 PaintContentEdge(canvas); | 312 PaintContentEdge(canvas); |
313 } | |
267 } | 314 } |
268 | 315 |
269 void BrowserNonClientFrameViewAsh::Layout() { | 316 void BrowserNonClientFrameViewAsh::Layout() { |
270 bool maximized_layout = UseShortHeader(); | 317 bool maximized_layout = UseShortHeader(); |
271 frame_painter_->LayoutHeader(this, maximized_layout); | 318 frame_painter_->LayoutHeader(this, maximized_layout); |
272 if (avatar_button()) | 319 if (avatar_button()) |
273 LayoutAvatar(); | 320 LayoutAvatar(); |
274 BrowserNonClientFrameView::Layout(); | 321 BrowserNonClientFrameView::Layout(); |
275 } | 322 } |
276 | 323 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 } | 389 } |
343 | 390 |
344 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { | 391 gfx::ImageSkia BrowserNonClientFrameViewAsh::GetFaviconForTabIconView() { |
345 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 392 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
346 if (!delegate) | 393 if (!delegate) |
347 return gfx::ImageSkia(); | 394 return gfx::ImageSkia(); |
348 return delegate->GetWindowIcon(); | 395 return delegate->GetWindowIcon(); |
349 } | 396 } |
350 | 397 |
351 /////////////////////////////////////////////////////////////////////////////// | 398 /////////////////////////////////////////////////////////////////////////////// |
399 // chrome::search::ToolbarSearchAnimator::Observer overrides: | |
400 | |
401 void BrowserNonClientFrameViewAsh::BackgroundChanging() { | |
402 // We're fading in the toolbar background, repaint the toolbar background. | |
403 browser_view()->toolbar()->SchedulePaint(); | |
404 } | |
405 | |
406 void BrowserNonClientFrameViewAsh::BackgroundChanged() { | |
407 // We've finished fading in the toolbar background, repaint the toolbar | |
408 // background. | |
409 browser_view()->toolbar()->SchedulePaint(); | |
410 } | |
411 | |
412 void BrowserNonClientFrameViewAsh::BackgroundChangeCanceled( | |
413 TabContents* tab_contents) { | |
414 // Fade in of toolbar background has been canceled, repaint the toolbar | |
415 // background. | |
416 browser_view()->toolbar()->SchedulePaint(); | |
417 } | |
418 | |
419 /////////////////////////////////////////////////////////////////////////////// | |
352 // BrowserNonClientFrameViewAsh, private: | 420 // BrowserNonClientFrameViewAsh, private: |
353 | 421 |
354 | 422 |
355 int BrowserNonClientFrameViewAsh::NonClientTopBorderHeight( | 423 int BrowserNonClientFrameViewAsh::NonClientTopBorderHeight( |
356 bool force_restored) const { | 424 bool force_restored) const { |
357 if (force_restored) | 425 if (force_restored) |
358 return tabstrip_top_spacing_tall(); | 426 return tabstrip_top_spacing_tall(); |
359 if (frame()->IsFullscreen()) | 427 if (frame()->IsFullscreen()) |
360 return 0; | 428 return 0; |
361 // Windows with tab strips need a smaller non-client area. | 429 // Windows with tab strips need a smaller non-client area. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
404 NonClientTopBorderHeight(false) + kContentShadowHeight: | 472 NonClientTopBorderHeight(false) + kContentShadowHeight: |
405 avatar_restored_y; | 473 avatar_restored_y; |
406 gfx::Rect avatar_bounds(kAvatarSideSpacing, | 474 gfx::Rect avatar_bounds(kAvatarSideSpacing, |
407 avatar_y, | 475 avatar_y, |
408 incognito_icon.width(), | 476 incognito_icon.width(), |
409 avatar_bottom - avatar_y); | 477 avatar_bottom - avatar_y); |
410 avatar_button()->SetBoundsRect(avatar_bounds); | 478 avatar_button()->SetBoundsRect(avatar_bounds); |
411 } | 479 } |
412 | 480 |
413 void BrowserNonClientFrameViewAsh::PaintToolbarBackground( | 481 void BrowserNonClientFrameViewAsh::PaintToolbarBackground( |
414 gfx::Canvas* canvas) { | 482 gfx::Canvas* canvas, |
483 chrome::search::Mode::Type mode) { | |
415 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); | 484 gfx::Rect toolbar_bounds(browser_view()->GetToolbarBounds()); |
416 if (toolbar_bounds.IsEmpty()) | 485 if (toolbar_bounds.IsEmpty()) |
417 return; | 486 return; |
418 gfx::Point toolbar_origin(toolbar_bounds.origin()); | 487 gfx::Point toolbar_origin(toolbar_bounds.origin()); |
419 ConvertPointToView(browser_view(), this, &toolbar_origin); | 488 ConvertPointToView(browser_view(), this, &toolbar_origin); |
420 toolbar_bounds.set_origin(toolbar_origin); | 489 toolbar_bounds.set_origin(toolbar_origin); |
421 | 490 |
422 int x = toolbar_bounds.x(); | 491 int x = toolbar_bounds.x(); |
423 int w = toolbar_bounds.width(); | 492 int w = toolbar_bounds.width(); |
424 int y = toolbar_bounds.y(); | 493 int y = toolbar_bounds.y(); |
425 int h = toolbar_bounds.height(); | 494 int h = toolbar_bounds.height(); |
426 | 495 |
427 // Gross hack: We split the toolbar images into two pieces, since sometimes | 496 // Gross hack: We split the toolbar images into two pieces, since sometimes |
428 // (popup mode) the toolbar isn't tall enough to show the whole image. The | 497 // (popup mode) the toolbar isn't tall enough to show the whole image. The |
429 // split happens between the top shadow section and the bottom gradient | 498 // split happens between the top shadow section and the bottom gradient |
430 // section so that we never break the gradient. | 499 // section so that we never break the gradient. |
431 int split_point = kFrameShadowThickness * 2; | 500 int split_point = kFrameShadowThickness * 2; |
432 int bottom_y = y + split_point; | 501 int bottom_y = y + split_point; |
433 ui::ThemeProvider* tp = GetThemeProvider(); | 502 ui::ThemeProvider* tp = GetThemeProvider(); |
434 int bottom_edge_height = h - split_point; | 503 int bottom_edge_height = h - split_point; |
435 | 504 |
505 SkColor background_color = GetToolbarBackgroundColor(mode); | |
436 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height), | 506 canvas->FillRect(gfx::Rect(x, bottom_y, w, bottom_edge_height), |
437 tp->GetColor(ThemeService::COLOR_TOOLBAR)); | 507 background_color); |
438 | 508 |
439 // Paint the main toolbar image. Since this image is also used to draw the | 509 // Paint the main toolbar image. Since this image is also used to draw the |
440 // tab background, we must use the tab strip offset to compute the image | 510 // tab background, we must use the tab strip offset to compute the image |
441 // source y position. If you have to debug this code use an image editor | 511 // source y position. If you have to debug this code use an image editor |
442 // to paint a diagonal line through the toolbar image and ensure it lines up | 512 // to paint a diagonal line through the toolbar image and ensure it lines up |
443 // across the tab and toolbar. | 513 // across the tab and toolbar. |
444 gfx::ImageSkia* theme_toolbar = tp->GetImageSkiaNamed(IDR_THEME_TOOLBAR); | 514 gfx::ImageSkia* theme_toolbar = GetToolbarBackgroundImage(mode); |
445 canvas->TileImageInt( | 515 canvas->TileImageInt( |
446 *theme_toolbar, | 516 *theme_toolbar, |
447 x, bottom_y - GetHorizontalTabStripVerticalOffset(false), | 517 x, bottom_y - GetHorizontalTabStripVerticalOffset(false), |
448 x, bottom_y, | 518 x, bottom_y, |
449 w, theme_toolbar->height()); | 519 w, theme_toolbar->height()); |
450 | 520 |
451 // The content area line has a shadow that extends a couple of pixels above | 521 // The content area line has a shadow that extends a couple of pixels above |
452 // the toolbar bounds. | 522 // the toolbar bounds. |
453 const int kContentShadowHeight = 2; | 523 const int kContentShadowHeight = 2; |
454 gfx::ImageSkia* toolbar_top = | 524 gfx::ImageSkia* toolbar_top = |
(...skipping 11 matching lines...) Expand all Loading... | |
466 y + kClientEdgeThickness + kContentShadowHeight, | 536 y + kClientEdgeThickness + kContentShadowHeight, |
467 toolbar_left->width(), theme_toolbar->height()); | 537 toolbar_left->width(), theme_toolbar->height()); |
468 gfx::ImageSkia* toolbar_right = | 538 gfx::ImageSkia* toolbar_right = |
469 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); | 539 tp->GetImageSkiaNamed(IDR_TOOLBAR_SHADE_RIGHT); |
470 canvas->TileImageInt(*toolbar_right, | 540 canvas->TileImageInt(*toolbar_right, |
471 0, 0, | 541 0, 0, |
472 w - toolbar_right->width() - 2 * kClientEdgeThickness, | 542 w - toolbar_right->width() - 2 * kClientEdgeThickness, |
473 y + kClientEdgeThickness + kContentShadowHeight, | 543 y + kClientEdgeThickness + kContentShadowHeight, |
474 toolbar_right->width(), theme_toolbar->height()); | 544 toolbar_right->width(), theme_toolbar->height()); |
475 | 545 |
476 // Draw the content/toolbar separator. | 546 // Only draw the content/toolbar separator if Instant Extended API is disabled |
477 canvas->FillRect(gfx::Rect(x + kClientEdgeThickness, | 547 // or mode is DEFAULT. |
478 toolbar_bounds.bottom() - kClientEdgeThickness, | 548 bool extended_instant_enabled = chrome::search::IsInstantExtendedAPIEnabled( |
479 w - (2 * kClientEdgeThickness), | 549 browser_view()->browser()->profile()); |
480 kClientEdgeThickness), | 550 if (!extended_instant_enabled || mode == chrome::search::Mode::MODE_DEFAULT) { |
481 ThemeService::GetDefaultColor(ThemeService::COLOR_TOOLBAR_SEPARATOR)); | 551 canvas->FillRect( |
552 gfx::Rect(x + kClientEdgeThickness, | |
553 toolbar_bounds.bottom() - kClientEdgeThickness, | |
554 w - (2 * kClientEdgeThickness), kClientEdgeThickness), | |
555 ThemeService::GetDefaultColor(extended_instant_enabled ? | |
556 ThemeService::COLOR_SEARCH_SEPARATOR_LINE : | |
557 ThemeService::COLOR_TOOLBAR_SEPARATOR)); | |
558 } | |
482 } | 559 } |
483 | 560 |
484 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { | 561 void BrowserNonClientFrameViewAsh::PaintContentEdge(gfx::Canvas* canvas) { |
485 canvas->FillRect(gfx::Rect(0, close_button_->bounds().bottom(), | 562 canvas->FillRect(gfx::Rect(0, close_button_->bounds().bottom(), |
486 width(), kClientEdgeThickness), | 563 width(), kClientEdgeThickness), |
487 ThemeService::GetDefaultColor(ThemeService::COLOR_TOOLBAR_SEPARATOR)); | 564 ThemeService::GetDefaultColor(ThemeService::COLOR_TOOLBAR_SEPARATOR)); |
488 } | 565 } |
489 | 566 |
490 int BrowserNonClientFrameViewAsh::GetThemeFrameImageId() const { | 567 int BrowserNonClientFrameViewAsh::GetThemeFrameImageId() const { |
491 bool is_incognito = browser_view()->IsOffTheRecord(); | 568 bool is_incognito = browser_view()->IsOffTheRecord(); |
(...skipping 21 matching lines...) Expand all Loading... | |
513 BrowserNonClientFrameViewAsh::GetThemeFrameOverlayImage() const { | 590 BrowserNonClientFrameViewAsh::GetThemeFrameOverlayImage() const { |
514 ui::ThemeProvider* tp = GetThemeProvider(); | 591 ui::ThemeProvider* tp = GetThemeProvider(); |
515 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && | 592 if (tp->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && |
516 browser_view()->IsBrowserTypeNormal() && | 593 browser_view()->IsBrowserTypeNormal() && |
517 !browser_view()->IsOffTheRecord()) { | 594 !browser_view()->IsOffTheRecord()) { |
518 return tp->GetImageSkiaNamed(ShouldPaintAsActive() ? | 595 return tp->GetImageSkiaNamed(ShouldPaintAsActive() ? |
519 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE); | 596 IDR_THEME_FRAME_OVERLAY : IDR_THEME_FRAME_OVERLAY_INACTIVE); |
520 } | 597 } |
521 return NULL; | 598 return NULL; |
522 } | 599 } |
OLD | NEW |