summaryrefslogtreecommitdiffstats
path: root/athena/activity/activity_frame_view.cc
blob: ca2e8be6036ce1227f10e624f5d42f3061236d5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "athena/activity/activity_frame_view.h"

#include <algorithm>
#include <vector>

#include "athena/activity/public/activity_view_model.h"
#include "ui/base/hit_test.h"
#include "ui/views/background.h"
#include "ui/views/controls/label.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"

namespace athena {

////////////////////////////////////////////////////////////////////////////////
// FrameViewAthena, public:

// static
const char ActivityFrameView::kViewClassName[] = "ActivityFrameView";

ActivityFrameView::ActivityFrameView(views::Widget* frame,
                                     ActivityViewModel* view_model)
    : frame_(frame), view_model_(view_model), title_(new views::Label) {
  title_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
  const gfx::FontList& font_list = title_->font_list();
  title_->SetFontList(font_list.Derive(1, gfx::Font::BOLD));
  title_->SetEnabledColor(SK_ColorBLACK);
  AddChildView(title_);
  UpdateWindowTitle();
}

ActivityFrameView::~ActivityFrameView() {
}

////////////////////////////////////////////////////////////////////////////////
// ActivityFrameView, views::NonClientFrameView overrides:

gfx::Rect ActivityFrameView::GetBoundsForClientView() const {
  gfx::Rect client_bounds = bounds();
  client_bounds.Inset(0, NonClientTopBorderHeight(), 0, 0);
  return client_bounds;
}

gfx::Rect ActivityFrameView::GetWindowBoundsForClientBounds(
    const gfx::Rect& client_bounds) const {
  gfx::Rect window_bounds = client_bounds;
  window_bounds.Inset(0, -NonClientTopBorderHeight(), 0, 0);
  return window_bounds;
}

int ActivityFrameView::NonClientHitTest(const gfx::Point& point) {
  if (frame_->IsFullscreen())
    return 0;
  if (title_->bounds().Contains(point))
    return HTCAPTION;
  return 0;
}

void ActivityFrameView::GetWindowMask(const gfx::Size& size,
                                      gfx::Path* window_mask) {
}

void ActivityFrameView::ResetWindowControls() {
}

void ActivityFrameView::UpdateWindowIcon() {
}

void ActivityFrameView::UpdateWindowTitle() {
  SkColor bgcolor = view_model_->GetRepresentativeColor();
  title_->set_background(views::Background::CreateSolidBackground(bgcolor));
  title_->SetBackgroundColor(bgcolor);
  title_->SetText(frame_->widget_delegate()->GetWindowTitle());
}

////////////////////////////////////////////////////////////////////////////////
// ActivityFrameView, views::View overrides:

gfx::Size ActivityFrameView::GetPreferredSize() const {
  gfx::Size pref = frame_->client_view()->GetPreferredSize();
  gfx::Rect bounds(0, 0, pref.width(), pref.height());
  return frame_->non_client_view()
      ->GetWindowBoundsForClientBounds(bounds)
      .size();
}

const char* ActivityFrameView::GetClassName() const {
  return kViewClassName;
}

void ActivityFrameView::Layout() {
  title_->SetBounds(0, 0, width(), NonClientTopBorderHeight());
}

////////////////////////////////////////////////////////////////////////////////
// ActivityFrameView, private:

int ActivityFrameView::NonClientTopBorderHeight() const {
  const int kDefaultTitleHeight = 25;
  return frame_->IsFullscreen() ? 0 : kDefaultTitleHeight;
}

}  // namespace ash