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

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

Issue 1547563003: Fix and simplify bookmark bar detach/attach animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years 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
« 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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_view.h" 5 #include "chrome/browser/ui/views/frame/browser_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 BookmarkBarView* bookmark_bar_view, 405 BookmarkBarView* bookmark_bar_view,
406 Browser* browser) 406 Browser* browser)
407 : browser_view_(browser_view), 407 : browser_view_(browser_view),
408 bookmark_bar_view_(bookmark_bar_view), 408 bookmark_bar_view_(bookmark_bar_view),
409 browser_(browser) { 409 browser_(browser) {
410 } 410 }
411 411
412 void BookmarkBarViewBackground::Paint(gfx::Canvas* canvas, 412 void BookmarkBarViewBackground::Paint(gfx::Canvas* canvas,
413 views::View* view) const { 413 views::View* view) const {
414 int toolbar_overlap = bookmark_bar_view_->GetToolbarOverlap(); 414 int toolbar_overlap = bookmark_bar_view_->GetToolbarOverlap();
415 if (!bookmark_bar_view_->IsDetached()) {
416 PaintAttachedBookmarkBar(canvas,
417 bookmark_bar_view_,
418 browser_view_,
419 browser_->host_desktop_type(),
420 toolbar_overlap);
421 return;
422 }
423 415
424 // As 'hidden' according to the animation is the full in-tab state, we invert 416 // As 'hidden' according to the animation is the full in-tab state, we invert
425 // the value - when current_state is at '0', we expect the bar to be docked. 417 // the value - when detach_percent is at '0', we expect the bar to be docked.
426 double current_state = 1 - bookmark_bar_view_->GetAnimationValue(); 418 double detach_percent = 1 - bookmark_bar_view_->GetAnimationValue();
Peter Kasting 2015/12/22 05:52:42 Nit: Since this is the only callsite for GetAnimat
Evan Stade 2015/12/29 17:14:16 I changed uint8 to SkAlpha and changed BookmarkBar
427 419 if (detach_percent != 1.0) {
428 if (current_state == 0.0 || current_state == 1.0) {
429 PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, browser_->profile());
430 return;
431 }
432 // While animating, set opacity to cross-fade between attached and detached
433 // backgrounds including their respective separators.
434 int detached_alpha = static_cast<uint8>(current_state * 255);
435 int attached_alpha = 255 - detached_alpha;
436 if (browser_->bookmark_bar_state() == BookmarkBar::DETACHED) {
437 // To animate from attached to detached state:
438 // - fade out attached background
439 // - fade in detached background.
440 canvas->SaveLayerAlpha(attached_alpha);
441 PaintAttachedBookmarkBar(canvas,
442 bookmark_bar_view_,
443 browser_view_,
444 browser_->host_desktop_type(),
445 toolbar_overlap);
446 canvas->Restore();
447 canvas->SaveLayerAlpha(detached_alpha);
448 PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, browser_->profile());
449 } else {
450 // To animate from detached to attached state:
451 // - fade out detached background
452 // - fade in attached background.
453 canvas->SaveLayerAlpha(detached_alpha);
454 PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, browser_->profile());
455 canvas->Restore();
456 canvas->SaveLayerAlpha(attached_alpha);
457 PaintAttachedBookmarkBar(canvas, 420 PaintAttachedBookmarkBar(canvas,
458 bookmark_bar_view_, 421 bookmark_bar_view_,
459 browser_view_, 422 browser_view_,
460 browser_->host_desktop_type(), 423 browser_->host_desktop_type(),
461 toolbar_overlap); 424 toolbar_overlap);
462 } 425 }
426
427 if (!bookmark_bar_view_->IsDetached() || detach_percent == 0.0)
428 return;
429
430 // While animating, set opacity to cross-fade between attached and detached
431 // backgrounds including their respective separators.
432 int detached_alpha = static_cast<uint8>(detach_percent * 255);
433 canvas->SaveLayerAlpha(detached_alpha);
434 PaintDetachedBookmarkBar(canvas, bookmark_bar_view_, browser_->profile());
463 canvas->Restore(); 435 canvas->Restore();
464 } 436 }
465 437
466 /////////////////////////////////////////////////////////////////////////////// 438 ///////////////////////////////////////////////////////////////////////////////
467 // BrowserView, public: 439 // BrowserView, public:
468 440
469 // static 441 // static
470 const char BrowserView::kViewClassName[] = "BrowserView"; 442 const char BrowserView::kViewClassName[] = "BrowserView";
471 443
472 BrowserView::BrowserView() 444 BrowserView::BrowserView()
(...skipping 2230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2703 return immersive_mode_controller()->IsEnabled(); 2675 return immersive_mode_controller()->IsEnabled();
2704 } 2676 }
2705 2677
2706 views::Widget* BrowserView::GetBubbleAssociatedWidget() { 2678 views::Widget* BrowserView::GetBubbleAssociatedWidget() {
2707 return GetWidget(); 2679 return GetWidget();
2708 } 2680 }
2709 2681
2710 gfx::Rect BrowserView::GetTopContainerBoundsInScreen() { 2682 gfx::Rect BrowserView::GetTopContainerBoundsInScreen() {
2711 return top_container_->GetBoundsInScreen(); 2683 return top_container_->GetBoundsInScreen();
2712 } 2684 }
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