summaryrefslogtreecommitdiffstats
path: root/views/window/dialog_delegate.cc
blob: aa94e87aed3f2ce3a699da796b3738ec2c1d7dc6 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) 2006-2008 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 "views/window/dialog_delegate.h"

#include "base/logging.h"
#include "views/controls/button/native_button.h"
#include "views/window/window.h"

namespace views {

// Overridden from WindowDelegate:

DialogDelegate* DialogDelegate::AsDialogDelegate() { return this; }

int DialogDelegate::GetDialogButtons() const {
  return ui::MessageBoxFlags::DIALOGBUTTON_OK |
      ui::MessageBoxFlags::DIALOGBUTTON_CANCEL;
}

bool DialogDelegate::AreAcceleratorsEnabled(
    ui::MessageBoxFlags::DialogButton button) {
  return true;
}

std::wstring DialogDelegate::GetDialogButtonLabel(
    ui::MessageBoxFlags::DialogButton button) const {
  // empty string results in defaults for
  // ui::MessageBoxFlags::DIALOGBUTTON_OK,
  // ui::MessageBoxFlags::DIALOGBUTTON_CANCEL.
  return L"";
}

View* DialogDelegate::GetExtraView() {
  return NULL;
}

bool DialogDelegate::GetSizeExtraViewHeightToButtons() {
  return false;
}

int DialogDelegate::GetDefaultDialogButton() const {
  if (GetDialogButtons() & MessageBoxFlags::DIALOGBUTTON_OK)
    return MessageBoxFlags::DIALOGBUTTON_OK;
  if (GetDialogButtons() & MessageBoxFlags::DIALOGBUTTON_CANCEL)
    return MessageBoxFlags::DIALOGBUTTON_CANCEL;
  return MessageBoxFlags::DIALOGBUTTON_NONE;
}

bool DialogDelegate::IsDialogButtonEnabled(
    ui::MessageBoxFlags::DialogButton button) const {
  return true;
}

bool DialogDelegate::IsDialogButtonVisible(
    ui::MessageBoxFlags::DialogButton button) const {
  return true;
}

bool DialogDelegate::Cancel() {
  return true;
}

bool DialogDelegate::Accept(bool window_closiang) {
  return Accept();
}

bool DialogDelegate::Accept() {
  return true;
}

View* DialogDelegate::GetInitiallyFocusedView() {
  // Focus the default button if any.
  DialogClientView* dcv = GetDialogClientView();
  int default_button = GetDefaultDialogButton();
  if (default_button == MessageBoxFlags::DIALOGBUTTON_NONE)
    return NULL;

  if ((default_button & GetDialogButtons()) == 0) {
    // The default button is a button we don't have.
    NOTREACHED();
    return NULL;
  }

  if (default_button & MessageBoxFlags::DIALOGBUTTON_OK)
    return dcv->ok_button();
  if (default_button & MessageBoxFlags::DIALOGBUTTON_CANCEL)
    return dcv->cancel_button();
  return NULL;
}

ClientView* DialogDelegate::CreateClientView(Window* window) {
  return new DialogClientView(window, GetContentsView());
}

DialogClientView* DialogDelegate::GetDialogClientView() const {
  return window()->client_view()->AsDialogClientView();
}

ui::AccessibilityTypes::Role DialogDelegate::GetAccessibleWindowRole() const {
  return ui::AccessibilityTypes::ROLE_DIALOG;
}

}  // namespace views