summaryrefslogtreecommitdiffstats
path: root/ui/views/controls/separator.cc
blob: e16346127ba4010be0e23670e856280dff926eda (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
// Copyright (c) 2012 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 "ui/views/controls/separator.h"

#include "ui/accessibility/ax_view_state.h"
#include "ui/gfx/canvas.h"

namespace views {

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

// The separator size in pixels.
const int kSeparatorSize = 1;

// Default color of the separator.
const SkColor kDefaultColor = SkColorSetARGB(255, 233, 233, 233);

Separator::Separator(Orientation orientation)
    : orientation_(orientation),
      color_(kDefaultColor),
      size_(kSeparatorSize) {
  SetFocusable(false);
}

Separator::~Separator() {
}

void Separator::SetColor(SkColor color) {
  color_ = color;
  SchedulePaint();
}

void Separator::SetPreferredSize(int size) {
  if (size != size_) {
    size_ = size;
    PreferredSizeChanged();
  }
}

////////////////////////////////////////////////////////////////////////////////
// Separator, View overrides:

gfx::Size Separator::GetPreferredSize() const {
  gfx::Size size =
      orientation_ == HORIZONTAL ? gfx::Size(1, size_) : gfx::Size(size_, 1);
  gfx::Insets insets = GetInsets();
  size.Enlarge(insets.width(), insets.height());
  return size;
}

void Separator::GetAccessibleState(ui::AXViewState* state) {
  state->role = ui::AX_ROLE_SPLITTER;
}

void Separator::OnPaint(gfx::Canvas* canvas) {
  canvas->FillRect(GetContentsBounds(), color_);
}

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

}  // namespace views