top_container_view.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
1// Copyright 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/frame/top_container_view.h" 6 7#include "chrome/browser/ui/views/frame/browser_frame.h" 8#include "chrome/browser/ui/views/frame/browser_view.h" 9#include "chrome/browser/ui/views/frame/immersive_mode_controller.h" 10 11TopContainerView::TopContainerView(BrowserView* browser_view) 12 : browser_view_(browser_view) { 13} 14 15TopContainerView::~TopContainerView() { 16} 17 18gfx::Rect TopContainerView::GetTargetBoundsInScreen() const { 19 if (!parent()) 20 return bounds(); 21 22 // Compute transform relative to parent. 23 gfx::Transform transform; 24 if (layer()) 25 transform = layer()->GetTargetTransform(); 26 gfx::Transform translation; 27 translation.Translate(static_cast<float>(GetMirroredX()), 28 static_cast<float>(y())); 29 transform.ConcatTransform(translation); 30 31 gfx::Point origin(parent()->GetBoundsInScreen().origin()); 32 transform.TransformPoint(origin); 33 return gfx::Rect(origin, size()); 34} 35 36gfx::Size TopContainerView::GetPreferredSize() { 37 // The view wants to be as wide as its parent and tall enough to fully show 38 // all its children. In particular, the bottom of the bookmark bar can be 39 // be above the bottom of the toolbar while the bookmark bar is animating. 40 int height = 0; 41 for (int i = 0; i < child_count(); ++i) { 42 int child_bottom = child_at(i)->bounds().bottom(); 43 if (child_bottom > height) 44 height = child_bottom; 45 } 46 return gfx::Size(browser_view_->width(), height); 47} 48 49std::string TopContainerView::GetClassName() const { 50 return "TopContainerView"; 51} 52 53void TopContainerView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 54 ImmersiveModeController* immersive_controller = 55 browser_view_->immersive_mode_controller(); 56 if (immersive_controller->IsEnabled()) 57 immersive_controller->OnTopContainerBoundsChanged(); 58} 59 60void TopContainerView::PaintChildren(gfx::Canvas* canvas) { 61 if (browser_view_->immersive_mode_controller()->IsRevealed()) { 62 // Top-views depend on parts of the frame (themes, window buttons) being 63 // painted underneath them. Clip rect has already been set to the bounds 64 // of this view, so just paint the frame. 65 views::View* frame = browser_view_->frame()->GetFrameView(); 66 frame->Paint(canvas); 67 } 68 69 views::View::PaintChildren(canvas); 70} 71