| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 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 "mash/browser/debug_view.h" | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "ui/gfx/canvas.h" | |
| 9 #include "ui/views/background.h" | |
| 10 #include "ui/views/controls/button/label_button.h" | |
| 11 #include "ui/views/controls/label.h" | |
| 12 #include "ui/views/controls/textfield/textfield.h" | |
| 13 #include "ui/views/layout/box_layout.h" | |
| 14 #include "ui/views/layout/fill_layout.h" | |
| 15 | |
| 16 namespace mash { | |
| 17 namespace browser { | |
| 18 | |
| 19 DebugView::DebugView() | |
| 20 : interstitial_container_(new views::View), | |
| 21 interstitial_label_( | |
| 22 new views::Label(base::ASCIIToUTF16("Interstitial: "))), | |
| 23 interstitial_show_( | |
| 24 new views::LabelButton(this, base::ASCIIToUTF16("Show"))), | |
| 25 interstitial_hide_( | |
| 26 new views::LabelButton(this, base::ASCIIToUTF16("Hide"))), | |
| 27 interstitial_content_(new views::Textfield) { | |
| 28 AddChildView(interstitial_container_); | |
| 29 interstitial_container_->AddChildView(interstitial_label_); | |
| 30 interstitial_container_->AddChildView(interstitial_show_); | |
| 31 interstitial_container_->AddChildView(interstitial_hide_); | |
| 32 interstitial_container_->AddChildView(interstitial_content_); | |
| 33 views::BoxLayout* layout = | |
| 34 new views::BoxLayout(views::BoxLayout::kHorizontal, 5, 5, 5); | |
| 35 interstitial_container_->SetLayoutManager(layout); | |
| 36 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
| 37 layout->set_cross_axis_alignment( | |
| 38 views::BoxLayout::CROSS_AXIS_ALIGNMENT_STRETCH); | |
| 39 layout->SetDefaultFlex(0); | |
| 40 layout->SetFlexForView(interstitial_content_, 1); | |
| 41 | |
| 42 set_background(views::Background::CreateStandardPanelBackground()); | |
| 43 SetLayoutManager(new views::FillLayout); | |
| 44 } | |
| 45 | |
| 46 DebugView::~DebugView() {} | |
| 47 | |
| 48 gfx::Size DebugView::GetPreferredSize() const { | |
| 49 return interstitial_container_->GetPreferredSize(); | |
| 50 } | |
| 51 | |
| 52 void DebugView::OnPaint(gfx::Canvas* canvas) { | |
| 53 gfx::Rect stroke_rect = GetLocalBounds(); | |
| 54 stroke_rect.set_height(1); | |
| 55 canvas->FillRect(stroke_rect, SK_ColorGRAY); | |
| 56 } | |
| 57 | |
| 58 void DebugView::ButtonPressed(views::Button* sender, const ui::Event& event) { | |
| 59 DCHECK(view_); | |
| 60 if (sender == interstitial_show_) { | |
| 61 view_->ShowInterstitial(base::UTF16ToUTF8(interstitial_content_->text())); | |
| 62 } else if (sender == interstitial_hide_) { | |
| 63 view_->HideInterstitial(); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 } // namespace browser | |
| 68 } // namespace mash | |
| OLD | NEW |