| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "mojo/examples/window_manager/debug_panel.h" | |
| 6 | |
| 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" | |
| 16 | |
| 17 namespace mojo { | |
| 18 namespace examples { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 const int kControlBorderInset = 5; | |
| 23 const int kNavigationTargetGroupId = 1; | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 DebugPanel::DebugPanel(Delegate* delegate, Shell* shell, View* view) | |
| 28 : delegate_(delegate), | |
| 29 view_(view), | |
| 30 navigation_target_label_( | |
| 31 new views::Label(base::ASCIIToUTF16("Navigation target:"))), | |
| 32 navigation_target_new_( | |
| 33 new views::RadioButton(base::ASCIIToUTF16("New window"), | |
| 34 kNavigationTargetGroupId)), | |
| 35 navigation_target_source_( | |
| 36 new views::RadioButton(base::ASCIIToUTF16("Source window"), | |
| 37 kNavigationTargetGroupId)), | |
| 38 navigation_target_default_( | |
| 39 new views::RadioButton(base::ASCIIToUTF16("Default"), | |
| 40 kNavigationTargetGroupId)), | |
| 41 colored_square_( | |
| 42 new views::BlueButton(this, base::ASCIIToUTF16("Local nav test"))), | |
| 43 close_last_( | |
| 44 new views::BlueButton(this, base::ASCIIToUTF16("Close last window"))), | |
| 45 cross_app_( | |
| 46 new views::BlueButton(this, | |
| 47 base::ASCIIToUTF16("Cross-app nav test"))) { | |
| 48 navigation_target_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 49 navigation_target_default_->SetChecked(true); | |
| 50 | |
| 51 views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView(); | |
| 52 widget_delegate->GetContentsView()->set_background( | |
| 53 views::Background::CreateSolidBackground(0xFFDDDDDD)); | |
| 54 widget_delegate->GetContentsView()->AddChildView(navigation_target_label_); | |
| 55 widget_delegate->GetContentsView()->AddChildView(navigation_target_default_); | |
| 56 widget_delegate->GetContentsView()->AddChildView(navigation_target_new_); | |
| 57 widget_delegate->GetContentsView()->AddChildView(navigation_target_source_); | |
| 58 widget_delegate->GetContentsView()->AddChildView(colored_square_); | |
| 59 widget_delegate->GetContentsView()->AddChildView(close_last_); | |
| 60 widget_delegate->GetContentsView()->AddChildView(cross_app_); | |
| 61 widget_delegate->GetContentsView()->SetLayoutManager(this); | |
| 62 | |
| 63 views::Widget* widget = new views::Widget(); | |
| 64 views::Widget::InitParams params( | |
| 65 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 66 params.native_widget = new NativeWidgetViewManager(widget, shell, view); | |
| 67 params.delegate = widget_delegate; | |
| 68 params.bounds = gfx::Rect(0, 0, view->bounds().width, view->bounds().height); | |
| 69 widget->Init(params); | |
| 70 widget->Show(); | |
| 71 } | |
| 72 | |
| 73 DebugPanel::~DebugPanel() { | |
| 74 } | |
| 75 | |
| 76 gfx::Size DebugPanel::GetPreferredSize(const views::View* view) const { | |
| 77 return gfx::Size(); | |
| 78 } | |
| 79 | |
| 80 Target DebugPanel::navigation_target() const { | |
| 81 if (navigation_target_new_->checked()) | |
| 82 return TARGET_NEW_NODE; | |
| 83 if (navigation_target_source_->checked()) | |
| 84 return TARGET_SOURCE_NODE; | |
| 85 return TARGET_DEFAULT; | |
| 86 } | |
| 87 | |
| 88 void DebugPanel::Layout(views::View* view) { | |
| 89 int y = kControlBorderInset; | |
| 90 int w = view->width() - kControlBorderInset * 2; | |
| 91 | |
| 92 navigation_target_label_->SetBounds( | |
| 93 kControlBorderInset, y, w, | |
| 94 navigation_target_label_->GetPreferredSize().height()); | |
| 95 y += navigation_target_label_->height(); | |
| 96 | |
| 97 views::RadioButton* radios[] = { | |
| 98 navigation_target_default_, | |
| 99 navigation_target_new_, | |
| 100 navigation_target_source_, | |
| 101 }; | |
| 102 for (size_t i = 0; i < arraysize(radios); ++i) { | |
| 103 radios[i]->SetBounds(kControlBorderInset, y, w, | |
| 104 radios[i]->GetPreferredSize().height()); | |
| 105 y += radios[i]->height(); | |
| 106 } | |
| 107 | |
| 108 y += kControlBorderInset; | |
| 109 views::Button* buttons[] = { | |
| 110 colored_square_, | |
| 111 close_last_, | |
| 112 cross_app_, | |
| 113 }; | |
| 114 for (size_t i = 0; i < arraysize(buttons); ++i) { | |
| 115 buttons[i]->SetBounds(kControlBorderInset, y, w, | |
| 116 buttons[i]->GetPreferredSize().height()); | |
| 117 y += buttons[i]->height(); | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 void DebugPanel::ButtonPressed(views::Button* sender, const ui::Event& event) { | |
| 122 if (sender == colored_square_) { | |
| 123 Navigate("mojo://embedded_app/"); | |
| 124 } else if (sender == close_last_) { | |
| 125 delegate_->CloseTopWindow(); | |
| 126 } else if (sender == cross_app_) { | |
| 127 Navigate("http://www.aaronboodman.com/z_dropbox/test.html"); | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 void DebugPanel::Navigate(const std::string& url) { | |
| 132 URLRequestPtr request(URLRequest::New()); | |
| 133 request->url = url; | |
| 134 delegate_->RequestNavigate(view_->id(), TARGET_NEW_NODE, request.Pass()); | |
| 135 } | |
| 136 | |
| 137 } // namespace examples | |
| 138 } // namespace mojo | |
| OLD | NEW |