top_container_view.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Copyright 2013 The Chromium Authors. All rights reserved.
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// Use of this source code is governed by a BSD-style license that can be
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org// found in the LICENSE file.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "chrome/browser/ui/views/frame/top_container_view.h"
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "chrome/browser/ui/views/frame/browser_frame.h"
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "chrome/browser/ui/views/frame/browser_view.h"
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgTopContainerView::TopContainerView(BrowserView* browser_view)
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    : browser_view_(browser_view) {
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgTopContainerView::~TopContainerView() {
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orggfx::Size TopContainerView::GetPreferredSize() {
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // The view wants to be as wide as its parent and tall enough to fully show
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // all its children. In particular, the bottom of the bookmark bar can be
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  // be above the bottom of the toolbar while the bookmark bar is animating.
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  int height = 0;
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  for (int i = 0; i < child_count(); ++i) {
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    views::View* child = child_at(i);
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (!child->visible())
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      continue;
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    int child_bottom = child->bounds().bottom();
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (child_bottom > height)
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      height = child_bottom;
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  if (browser_view_->immersive_mode_controller()->IsRevealed()) {
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // In immersive fullscreen, the TopContainerView paints the window header
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // (themes, window title, window controls). The TopContainerView must still
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // paint these even if it does not have any visible children.
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    height = std::max(height, browser_view_->frame()->GetTopInset());
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return gfx::Size(browser_view_->width(), height);
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgconst char* TopContainerView::GetClassName() const {
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  return "TopContainerView";
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid TopContainerView::OnPaintBackground(gfx::Canvas* canvas) {
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  if (browser_view_->immersive_mode_controller()->IsRevealed()) {
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // Top-views depend on parts of the frame (themes, window title,
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // window controls) being painted underneath them. Clip rect has already
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    // been set to the bounds of this view, so just paint the frame.
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    views::View* frame = browser_view_->frame()->GetFrameView();
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    frame->Paint(canvas);
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org  }
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org