summaryrefslogtreecommitdiffstats
path: root/athena/main/athena_frame_view.cc
blob: 5422a0c04825ebed49250842a77f8b5e5c7a9d6d (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
// 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/main/athena_frame_view.h"

#include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkColor.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"
#include "ui/views/window/client_view.h"

namespace athena {
namespace {

// The height of the top border necessary to display the title without the icon.
const int kDefaultTitleHeight = 13;

// The default background color for athena's frame. This is placeholder.
const SkColor kDefaultTitleBackground = 0xFFcccccc;

}  // namespace

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

AthenaFrameView::AthenaFrameView(views::Widget* frame) : frame_(frame) {
  set_background(
      views::Background::CreateSolidBackground(kDefaultTitleBackground));
  UpdateWindowTitle();
}

AthenaFrameView::~AthenaFrameView() {
}

gfx::Rect AthenaFrameView::GetBoundsForClientView() const {
  gfx::Rect client_bounds = bounds();
  client_bounds.Inset(NonClientBorderInsets());
  return client_bounds;
}

gfx::Rect AthenaFrameView::GetWindowBoundsForClientBounds(
    const gfx::Rect& client_bounds) const {
  gfx::Rect window_bounds = client_bounds;
  window_bounds.Inset(-NonClientBorderInsets());
  return window_bounds;
}

int AthenaFrameView::NonClientHitTest(const gfx::Point& point) {
  if (!bounds().Contains(point))
    return HTNOWHERE;
  int client_hit_test = frame_->client_view()->NonClientHitTest(point);
  if (client_hit_test != HTNOWHERE)
    return client_hit_test;
  int window_hit_test =
      GetHTComponentForFrame(point, 0, NonClientBorderThickness(), 0, 0, false);
  return (window_hit_test == HTNOWHERE) ? HTCAPTION : client_hit_test;
}

gfx::Size AthenaFrameView::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* AthenaFrameView::GetClassName() const {
  return kViewClassName;
}

gfx::Insets AthenaFrameView::NonClientBorderInsets() const {
  int border_thickness = NonClientBorderThickness();
  return gfx::Insets(NonClientTopBorderHeight(),
                     border_thickness,
                     border_thickness,
                     border_thickness);
}

int AthenaFrameView::NonClientBorderThickness() const {
  return 0;
}

int AthenaFrameView::NonClientTopBorderHeight() const {
  return kDefaultTitleHeight;
}

}  // namespace athena