border.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 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#ifndef UI_VIEWS_BORDER_H_ 6#define UI_VIEWS_BORDER_H_ 7 8#include "base/basictypes.h" 9#include "third_party/skia/include/core/SkColor.h" 10#include "ui/gfx/insets.h" 11#include "ui/views/view.h" 12#include "ui/views/views_export.h" 13 14namespace gfx{ 15class Canvas; 16} 17 18namespace views { 19 20class Painter; 21class View; 22 23//////////////////////////////////////////////////////////////////////////////// 24// 25// Border class. 26// 27// The border class is used to display a border around a view. 28// To set a border on a view, just call SetBorder on the view, for example: 29// view->set_border(Border::CreateSolidBorder(1, SkColorSetRGB(25, 25, 112)); 30// Once set on a view, the border is owned by the view. 31// 32// IMPORTANT NOTE: not all views support borders at this point. In order to 33// support the border, views should make sure to use bounds excluding the 34// border (by calling View::GetLocalBoundsExcludingBorder) when doing layout and 35// painting. 36// 37//////////////////////////////////////////////////////////////////////////////// 38 39class VIEWS_EXPORT Border { 40 public: 41 Border(); 42 virtual ~Border(); 43 44 // Creates a border that is a simple line of the specified thickness and 45 // color. 46 static Border* CreateSolidBorder(int thickness, SkColor color); 47 48 // Creates a border for reserving space. The returned border does not 49 // paint anything. 50 static Border* CreateEmptyBorder(int top, int left, int bottom, int right); 51 52 // Creates a border of the specified color, and specified thickness on each 53 // side. 54 static Border* CreateSolidSidedBorder(int top, 55 int left, 56 int bottom, 57 int right, 58 SkColor color); 59 60 // Creates a Border from the specified Painter. The border owns the painter, 61 // thus the painter is deleted when the Border is deleted. 62 static Border* CreateBorderPainter(Painter* painter); 63 64 // Renders the border for the specified view. 65 virtual void Paint(const View& view, gfx::Canvas* canvas) = 0; 66 67 // Sets the specified insets to the the border insets. 68 virtual void GetInsets(gfx::Insets* insets) const = 0; 69 70 private: 71 DISALLOW_COPY_AND_ASSIGN(Border); 72}; 73 74} // namespace views 75 76#endif // UI_VIEWS_BORDER_H_ 77