Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add property to accessible BrowserWindow window title #19698

Merged
merged 5 commits into from Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/api/browser-window.md
Expand Up @@ -1227,6 +1227,16 @@ Returns `String` - The title of the native window.
**Note:** The title of the web page can be different from the title of the native
window.

#### `win.setAccessibleTitle(title)`
mshoho marked this conversation as resolved.
Show resolved Hide resolved

* `title` String

Changes the accessible title of native window to `title`.

#### `win.getAccessibleTitle()`

Returns `String` - The accessible title of native window (or an empty string if none).

#### `win.setSheetOffset(offsetY[, offsetX])` _macOS_

* `offsetY` Float
Expand Down
10 changes: 10 additions & 0 deletions shell/browser/api/atom_api_top_level_window.cc
Expand Up @@ -565,6 +565,14 @@ std::string TopLevelWindow::GetTitle() {
return window_->GetTitle();
}

void TopLevelWindow::SetAccessibleTitle(const std::string& title) {
window_->SetAccessibleTitle(title);
}

std::string TopLevelWindow::GetAccessibleTitle() {
return window_->GetAccessibleTitle();
}

void TopLevelWindow::FlashFrame(bool flash) {
window_->FlashFrame(flash);
}
Expand Down Expand Up @@ -1108,6 +1116,8 @@ void TopLevelWindow::BuildPrototype(v8::Isolate* isolate,
.SetMethod("getPosition", &TopLevelWindow::GetPosition)
.SetMethod("setTitle", &TopLevelWindow::SetTitle)
.SetMethod("getTitle", &TopLevelWindow::GetTitle)
.SetMethod("setAccessibleTitle", &TopLevelWindow::SetAccessibleTitle)
mshoho marked this conversation as resolved.
Show resolved Hide resolved
.SetMethod("getAccessibleTitle", &TopLevelWindow::GetAccessibleTitle)
.SetMethod("flashFrame", &TopLevelWindow::FlashFrame)
.SetMethod("setSkipTaskbar", &TopLevelWindow::SetSkipTaskbar)
.SetMethod("setSimpleFullScreen", &TopLevelWindow::SetSimpleFullScreen)
Expand Down
2 changes: 2 additions & 0 deletions shell/browser/api/atom_api_top_level_window.h
Expand Up @@ -144,6 +144,8 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
std::vector<int> GetPosition();
void SetTitle(const std::string& title);
std::string GetTitle();
void SetAccessibleTitle(const std::string& title);
std::string GetAccessibleTitle();
void FlashFrame(bool flash);
void SetSkipTaskbar(bool skip);
void SetExcludedFromShownWindowsMenu(bool excluded);
Expand Down
16 changes: 16 additions & 0 deletions shell/browser/native_window.cc
Expand Up @@ -582,6 +582,22 @@ const views::Widget* NativeWindow::GetWidget() const {
return widget();
}

base::string16 NativeWindow::GetAccessibleWindowTitle() const {
mshoho marked this conversation as resolved.
Show resolved Hide resolved
codebytere marked this conversation as resolved.
Show resolved Hide resolved
if (accessible_title_.empty()) {
return views::WidgetDelegate::GetAccessibleWindowTitle();
}

return base::UTF8ToUTF16(accessible_title_);
mshoho marked this conversation as resolved.
Show resolved Hide resolved
}

void NativeWindow::SetAccessibleTitle(const std::string& title) {
accessible_title_ = title;
}

std::string NativeWindow::GetAccessibleTitle() {
return accessible_title_;
}

// static
void NativeWindowRelay::CreateForWebContents(
content::WebContents* web_contents,
Expand Down
9 changes: 9 additions & 0 deletions shell/browser/native_window.h
Expand Up @@ -132,6 +132,12 @@ class NativeWindow : public base::SupportsUserData,
virtual void Invalidate() = 0;
virtual void SetTitle(const std::string& title) = 0;
virtual std::string GetTitle() = 0;

// Ability to augment the window title for the screen readers.
base::string16 GetAccessibleWindowTitle() const override;
mshoho marked this conversation as resolved.
Show resolved Hide resolved
void SetAccessibleTitle(const std::string& title);
std::string GetAccessibleTitle();

virtual void FlashFrame(bool flash) = 0;
virtual void SetSkipTaskbar(bool skip) = 0;
virtual void SetExcludedFromShownWindowsMenu(bool excluded) = 0;
Expand Down Expand Up @@ -352,6 +358,9 @@ class NativeWindow : public base::SupportsUserData,
// Observers of this window.
base::ObserverList<NativeWindowObserver> observers_;

// Accessible title.
std::string accessible_title_;

base::WeakPtrFactory<NativeWindow> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(NativeWindow);
Expand Down