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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
// 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 "mojo/examples/window_manager/debug_panel.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/views/native_widget_view_manager.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/button/radio_button.h"
#include "ui/views/widget/widget.h"
namespace mojo {
namespace examples {
namespace {
const int kControlBorderInset = 5;
const int kNavigationTargetGroupId = 1;
} // namespace
DebugPanel::DebugPanel(Delegate* delegate, view_manager::Node* node)
: delegate_(delegate),
node_(node),
navigation_target_label_(new views::Label(
base::ASCIIToUTF16("Navigation target:"))),
navigation_target_new_(new views::RadioButton(
base::ASCIIToUTF16("New window"), kNavigationTargetGroupId)),
navigation_target_source_(new views::RadioButton(
base::ASCIIToUTF16("Source window"), kNavigationTargetGroupId)),
navigation_target_default_(new views::RadioButton(
base::ASCIIToUTF16("Default"), kNavigationTargetGroupId)),
next_color_(0),
colored_square_(new views::BlueButton(
this, base::ASCIIToUTF16("Local nav test"))),
close_last_(new views::BlueButton(
this, base::ASCIIToUTF16("Close last window"))),
cross_app_(new views::BlueButton(
this, base::ASCIIToUTF16("Cross-app nav test"))) {
navigation_target_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
navigation_target_default_->SetChecked(true);
views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView();
widget_delegate->GetContentsView()->set_background(
views::Background::CreateSolidBackground(0xFFDDDDDD));
widget_delegate->GetContentsView()->AddChildView(navigation_target_label_);
widget_delegate->GetContentsView()->AddChildView(navigation_target_default_);
widget_delegate->GetContentsView()->AddChildView(navigation_target_new_);
widget_delegate->GetContentsView()->AddChildView(navigation_target_source_);
widget_delegate->GetContentsView()->AddChildView(colored_square_);
widget_delegate->GetContentsView()->AddChildView(close_last_);
widget_delegate->GetContentsView()->AddChildView(cross_app_);
widget_delegate->GetContentsView()->SetLayoutManager(this);
views::Widget* widget = new views::Widget();
views::Widget::InitParams params(
views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.native_widget = new NativeWidgetViewManager(widget, node);
params.delegate = widget_delegate;
params.bounds = gfx::Rect(node->bounds().size());
widget->Init(params);
widget->Show();
}
DebugPanel::~DebugPanel() {
}
gfx::Size DebugPanel::GetPreferredSize(const views::View* view) const {
return gfx::Size();
}
navigation::Target DebugPanel::navigation_target() const {
if (navigation_target_new_->checked())
return navigation::TARGET_NEW_NODE;
if (navigation_target_source_->checked())
return navigation::TARGET_SOURCE_NODE;
return navigation::TARGET_DEFAULT;
}
void DebugPanel::Layout(views::View* view) {
int y = kControlBorderInset;
int w = view->width() - kControlBorderInset * 2;
navigation_target_label_->SetBounds(
kControlBorderInset, y, w,
navigation_target_label_->GetPreferredSize().height());
y += navigation_target_label_->height();
views::RadioButton* radios[] = {
navigation_target_default_,
navigation_target_new_,
navigation_target_source_,
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(radios); ++i) {
radios[i]->SetBounds(kControlBorderInset, y, w,
radios[i]->GetPreferredSize().height());
y += radios[i]->height();
}
y += kControlBorderInset;
views::Button* buttons[] = {
colored_square_,
close_last_,
cross_app_,
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(buttons); ++i) {
buttons[i]->SetBounds(kControlBorderInset, y, w,
buttons[i]->GetPreferredSize().height());
y += buttons[i]->height();
}
}
void DebugPanel::ButtonPressed(views::Button* sender, const ui::Event& event) {
if (sender == colored_square_) {
Navigate(base::StringPrintf("mojo://mojo_embedded_app/%x",
kColors[next_color_ % arraysize(kColors)]));
next_color_++;
} else if (sender == close_last_) {
delegate_->CloseTopWindow();
} else if (sender == cross_app_) {
Navigate("http://www.aaronboodman.com/z_dropbox/test.html");
}
}
void DebugPanel::Navigate(const std::string& url) {
navigation::NavigationDetailsPtr details(
navigation::NavigationDetails::New());
details->url = url;
delegate_->RequestNavigate(
node_->id(), navigation::TARGET_NEW_NODE, details.Pass());
}
} // namespace examples
} // namespace mojo
|