open_pdf_in_reader_bubble_view.cc revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file.
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/views/open_pdf_in_reader_bubble_view.h"
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h"
85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "grit/generated_resources.h"
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/button/label_button.h"
115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/label.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/link.h"
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/controls/separator.h"
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/views/layout/grid_layout.h"
1546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "ui/views/layout/layout_constants.h"
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)OpenPDFInReaderBubbleView::~OpenPDFInReaderBubbleView() {}
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)OpenPDFInReaderBubbleView::OpenPDFInReaderBubbleView(
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    views::View* anchor_view,
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    OpenPDFInReaderPromptDelegate* model)
225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      model_(model),
24effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      open_in_reader_link_(NULL),
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      close_button_(NULL) {
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK(model);
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
286e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void OpenPDFInReaderBubbleView::Init() {
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  using views::GridLayout;
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GridLayout* layout = new views::GridLayout(this);
3346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  SetLayoutManager(layout);
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
3546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  const int single_column_set_id = 0;
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  views::ColumnSet* column_set = layout->AddColumnSet(single_column_set_id);
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  column_set->AddColumn(GridLayout::LEADING, GridLayout::FILL, 1,
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                        GridLayout::USE_PREF, 0, 0);
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 title = model_->GetMessageText();
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  views::Label* title_label = new views::Label(title);
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->StartRow(0, single_column_set_id);
4346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  layout->AddView(title_label);
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  base::string16 accept_text = model_->GetAcceptButtonText();
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  open_in_reader_link_ = new views::Link(accept_text);
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  open_in_reader_link_->SetEnabled(true);
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  open_in_reader_link_->set_listener(this);
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->StartRow(0, single_column_set_id);
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->AddView(open_in_reader_link_);
535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->StartRow(0, single_column_set_id);
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->AddView(new views::Separator(views::Separator::HORIZONTAL), 1, 1,
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                  GridLayout::FILL, GridLayout::FILL);
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  close_button_ = new views::LabelButton(this, model_->GetCancelButtonText());
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->StartRow(0, single_column_set_id);
635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  layout->AddView(close_button_);
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void OpenPDFInReaderBubbleView::ButtonPressed(views::Button* sender,
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                              const ui::Event& event) {
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK_EQ(close_button_, sender);
69a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  model_->Cancel();
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  StartFade(false);
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)void OpenPDFInReaderBubbleView::LinkClicked(views::Link* source,
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                                            int event_flags) {
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  DCHECK_EQ(open_in_reader_link_, source);
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  model_->Accept();
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  StartFade(false);
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
8146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)