summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/views/open_pdf_in_reader_bubble_view.cc
blob: 99b34a12015e3dddc1bd8824003a094b826f0fa5 (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
72
73
74
75
76
77
78
// Copyright (c) 2012 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/open_pdf_in_reader_bubble_view.h"

#include "components/pdf/browser/open_pdf_in_reader_prompt_client.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"

OpenPDFInReaderBubbleView::~OpenPDFInReaderBubbleView() {}

OpenPDFInReaderBubbleView::OpenPDFInReaderBubbleView(
    views::View* anchor_view,
    pdf::OpenPDFInReaderPromptClient* model)
    : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
      model_(model),
      open_in_reader_link_(NULL),
      close_button_(NULL) {
  DCHECK(model);
}

void OpenPDFInReaderBubbleView::Init() {
  using views::GridLayout;

  GridLayout* layout = new views::GridLayout(this);
  SetLayoutManager(layout);

  const int single_column_set_id = 0;
  views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id);
  column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
                        GridLayout::USE_PREF, 0, 0);

  base::string16 title = model_->GetMessageText();
  views::Label* title_label = new views::Label(title);
  layout->StartRow(0, single_column_set_id);
  layout->AddView(title_label);

  layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);

  base::string16 accept_text = model_->GetAcceptButtonText();
  open_in_reader_link_ = new views::Link(accept_text);
  open_in_reader_link_->set_listener(this);
  layout->StartRow(0, single_column_set_id);
  layout->AddView(open_in_reader_link_);

  layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
  layout->StartRow(0, single_column_set_id);
  layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1,
                  GridLayout::FILL, GridLayout::FILL);
  layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);

  close_button_ = new views::LabelButton(this, model_->GetCancelButtonText());
  close_button_->SetStyle(views::Button::STYLE_BUTTON);
  layout->StartRow(0, single_column_set_id);
  layout->AddView(close_button_);
}

void OpenPDFInReaderBubbleView::ButtonPressed(views::Button* sender,
                                              const ui::Event& event) {
  DCHECK_EQ(close_button_, sender);

  model_->Cancel();
  GetWidget()->Close();
}

void OpenPDFInReaderBubbleView::LinkClicked(views::Link* source,
                                            int event_flags) {
  DCHECK_EQ(open_in_reader_link_, source);

  model_->Accept();
  GetWidget()->Close();
}