blob: 2cc086cdccde876def6fd65aecb2d3927cc4d9c0 (
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
|
// Copyright (c) 2011 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 "chrome/browser/ui/views/options/managed_prefs_banner_view.h"
#include "gfx/color_utils.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "ui/base/resource/resource_bundle.h"
#include "views/box_layout.h"
#include "views/controls/image_view.h"
#include "views/controls/label.h"
#include "views/standard_layout.h"
// Spacing between the banner frame and its contents.
static const int kPrefsBannerPadding = 3;
// Width of the banner frame.
static const int kPrefsBannerBorderSize = 1;
ManagedPrefsBannerView::ManagedPrefsBannerView(PrefService* prefs,
OptionsPage page)
: policy::ManagedPrefsBannerBase(prefs, page) {
content_ = new views::View;
SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW);
views::Border* border = views::Border::CreateSolidBorder(
kPrefsBannerBorderSize, border_color);
content_->set_border(border);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
warning_image_ = new views::ImageView();
warning_image_->SetImage(rb.GetBitmapNamed(IDR_WARNING));
label_ = new views::Label(rb.GetLocalizedString(IDS_OPTIONS_MANAGED_PREFS));
}
void ManagedPrefsBannerView::Init() {
AddChildView(content_);
content_->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kHorizontal,
kPrefsBannerPadding,
kPrefsBannerPadding,
kRelatedControlSmallHorizontalSpacing));
content_->AddChildView(warning_image_);
content_->AddChildView(label_);
OnUpdateVisibility();
}
gfx::Size ManagedPrefsBannerView::GetPreferredSize() {
if (!IsVisible())
return gfx::Size();
// Add space below the banner.
gfx::Size size(content_->GetPreferredSize());
size.Enlarge(0, kRelatedControlVerticalSpacing);
return size;
}
void ManagedPrefsBannerView::Layout() {
content_->SetBounds(0, 0, width(), height() - kRelatedControlVerticalSpacing);
}
void ManagedPrefsBannerView::ViewHierarchyChanged(bool is_add,
views::View* parent,
views::View* child) {
if (is_add && child == this)
Init();
}
void ManagedPrefsBannerView::OnUpdateVisibility() {
SetVisible(DetermineVisibility());
}
|