Introduce new SPDY Version UMA histogram.
[chromium-blink-merge.git] / mojo / examples / window_manager / debug_panel.cc
blobc65785c7be7e1f1ec4ee0bac76fa63e27dac05ce
1 // Copyright 2014 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.
5 #include "mojo/examples/window_manager/debug_panel.h"
7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "mojo/services/public/cpp/view_manager/view.h"
10 #include "mojo/views/native_widget_view_manager.h"
11 #include "ui/gfx/text_constants.h"
12 #include "ui/views/background.h"
13 #include "ui/views/controls/button/blue_button.h"
14 #include "ui/views/controls/button/radio_button.h"
15 #include "ui/views/widget/widget.h"
17 namespace mojo {
18 namespace examples {
20 namespace {
22 const int kControlBorderInset = 5;
23 const int kNavigationTargetGroupId = 1;
25 } // namespace
27 DebugPanel::DebugPanel(Delegate* delegate, View* view)
28 : delegate_(delegate),
29 view_(view),
30 navigation_target_label_(new views::Label(
31 base::ASCIIToUTF16("Navigation target:"))),
32 navigation_target_new_(new views::RadioButton(
33 base::ASCIIToUTF16("New window"), kNavigationTargetGroupId)),
34 navigation_target_source_(new views::RadioButton(
35 base::ASCIIToUTF16("Source window"), kNavigationTargetGroupId)),
36 navigation_target_default_(new views::RadioButton(
37 base::ASCIIToUTF16("Default"), kNavigationTargetGroupId)),
38 colored_square_(new views::BlueButton(
39 this, base::ASCIIToUTF16("Local nav test"))),
40 close_last_(new views::BlueButton(
41 this, base::ASCIIToUTF16("Close last window"))),
42 cross_app_(new views::BlueButton(
43 this, base::ASCIIToUTF16("Cross-app nav test"))) {
44 navigation_target_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
45 navigation_target_default_->SetChecked(true);
47 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView();
48 widget_delegate->GetContentsView()->set_background(
49 views::Background::CreateSolidBackground(0xFFDDDDDD));
50 widget_delegate->GetContentsView()->AddChildView(navigation_target_label_);
51 widget_delegate->GetContentsView()->AddChildView(navigation_target_default_);
52 widget_delegate->GetContentsView()->AddChildView(navigation_target_new_);
53 widget_delegate->GetContentsView()->AddChildView(navigation_target_source_);
54 widget_delegate->GetContentsView()->AddChildView(colored_square_);
55 widget_delegate->GetContentsView()->AddChildView(close_last_);
56 widget_delegate->GetContentsView()->AddChildView(cross_app_);
57 widget_delegate->GetContentsView()->SetLayoutManager(this);
59 views::Widget* widget = new views::Widget();
60 views::Widget::InitParams params(
61 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
62 params.native_widget = new NativeWidgetViewManager(widget, view);
63 params.delegate = widget_delegate;
64 params.bounds = gfx::Rect(view->bounds().size());
65 widget->Init(params);
66 widget->Show();
69 DebugPanel::~DebugPanel() {
72 gfx::Size DebugPanel::GetPreferredSize(const views::View* view) const {
73 return gfx::Size();
76 Target DebugPanel::navigation_target() const {
77 if (navigation_target_new_->checked())
78 return TARGET_NEW_NODE;
79 if (navigation_target_source_->checked())
80 return TARGET_SOURCE_NODE;
81 return TARGET_DEFAULT;
84 void DebugPanel::Layout(views::View* view) {
85 int y = kControlBorderInset;
86 int w = view->width() - kControlBorderInset * 2;
88 navigation_target_label_->SetBounds(
89 kControlBorderInset, y, w,
90 navigation_target_label_->GetPreferredSize().height());
91 y += navigation_target_label_->height();
93 views::RadioButton* radios[] = {
94 navigation_target_default_,
95 navigation_target_new_,
96 navigation_target_source_,
98 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(radios); ++i) {
99 radios[i]->SetBounds(kControlBorderInset, y, w,
100 radios[i]->GetPreferredSize().height());
101 y += radios[i]->height();
104 y += kControlBorderInset;
105 views::Button* buttons[] = {
106 colored_square_,
107 close_last_,
108 cross_app_,
110 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(buttons); ++i) {
111 buttons[i]->SetBounds(kControlBorderInset, y, w,
112 buttons[i]->GetPreferredSize().height());
113 y += buttons[i]->height();
117 void DebugPanel::ButtonPressed(views::Button* sender, const ui::Event& event) {
118 if (sender == colored_square_) {
119 Navigate("mojo://mojo_embedded_app/");
120 } else if (sender == close_last_) {
121 delegate_->CloseTopWindow();
122 } else if (sender == cross_app_) {
123 Navigate("http://www.aaronboodman.com/z_dropbox/test.html");
127 void DebugPanel::Navigate(const std::string& url) {
128 URLRequestPtr request(URLRequest::New());
129 request->url = url;
130 delegate_->RequestNavigate(view_->id(), TARGET_NEW_NODE, request.Pass());
133 } // namespace examples
134 } // namespace mojo