mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-27 01:17:43 +01:00
views: cefclient: Fix initial toolbar button state
This commit is contained in:
parent
8ba22e9e11
commit
6253e69b70
@ -128,6 +128,12 @@ CefBrowserViewDelegate::ChromeToolbarType CalculateChromeToolbarType(
|
|||||||
return with_overlay_controls ? CEF_CTT_LOCATION : CEF_CTT_NORMAL;
|
return with_overlay_controls ? CEF_CTT_LOCATION : CEF_CTT_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetViewEnabled(CefRefPtr<CefWindow> window, int id, bool enable) {
|
||||||
|
if (auto view = window->GetViewForID(id)) {
|
||||||
|
view->SetEnabled(enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// static
|
// static
|
||||||
@ -312,18 +318,19 @@ void ViewsWindow::SetLoadingState(bool isLoading,
|
|||||||
bool canGoBack,
|
bool canGoBack,
|
||||||
bool canGoForward) {
|
bool canGoForward) {
|
||||||
CEF_REQUIRE_UI_THREAD();
|
CEF_REQUIRE_UI_THREAD();
|
||||||
|
|
||||||
|
is_loading_ = isLoading;
|
||||||
|
can_go_back_ = canGoBack;
|
||||||
|
can_go_forward_ = canGoForward;
|
||||||
|
|
||||||
if (!window_ || chrome_toolbar_type_ == CEF_CTT_NORMAL) {
|
if (!window_ || chrome_toolbar_type_ == CEF_CTT_NORMAL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (with_controls_) {
|
// |toolbar_| may be nullptr for the initial notification after CefBrowser
|
||||||
EnableView(ID_BACK_BUTTON, canGoBack);
|
// creation, in which case the initial state will be appled in AddControls.
|
||||||
EnableView(ID_FORWARD_BUTTON, canGoForward);
|
if (with_controls_ && toolbar_) {
|
||||||
EnableView(ID_RELOAD_BUTTON, !isLoading);
|
UpdateToolbarButtonState();
|
||||||
EnableView(ID_STOP_BUTTON, isLoading);
|
|
||||||
}
|
|
||||||
if (location_bar_) {
|
|
||||||
EnableView(ID_URL_TEXTFIELD, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,7 +733,8 @@ void ViewsWindow::OnWindowCreated(CefRefPtr<CefWindow> window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (with_controls_) {
|
if (with_controls_) {
|
||||||
// Add the BrowserView and other controls to the Window.
|
// Add the BrowserView to the Window. Other controls will be added after the
|
||||||
|
// BrowserView is added.
|
||||||
AddBrowserView();
|
AddBrowserView();
|
||||||
|
|
||||||
// Add keyboard accelerators to the Window.
|
// Add keyboard accelerators to the Window.
|
||||||
@ -1194,7 +1202,6 @@ CefRefPtr<CefView> ViewsWindow::CreateLocationBar() {
|
|||||||
// Create the URL textfield.
|
// Create the URL textfield.
|
||||||
CefRefPtr<CefTextfield> url_textfield = CefTextfield::CreateTextfield(this);
|
CefRefPtr<CefTextfield> url_textfield = CefTextfield::CreateTextfield(this);
|
||||||
url_textfield->SetID(ID_URL_TEXTFIELD);
|
url_textfield->SetID(ID_URL_TEXTFIELD);
|
||||||
url_textfield->SetEnabled(false); // Disabled by default.
|
|
||||||
location_bar_ = url_textfield;
|
location_bar_ = url_textfield;
|
||||||
}
|
}
|
||||||
return location_bar_;
|
return location_bar_;
|
||||||
@ -1320,6 +1327,10 @@ void ViewsWindow::AddControls() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
minimum_window_size_ = CefSize(min_width, min_height);
|
minimum_window_size_ = CefSize(min_width, min_height);
|
||||||
|
|
||||||
|
// Apply the state that we may have missed when SetLoadingState was called
|
||||||
|
// initially.
|
||||||
|
UpdateToolbarButtonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewsWindow::AddAccelerators() {
|
void ViewsWindow::AddAccelerators() {
|
||||||
@ -1349,17 +1360,11 @@ void ViewsWindow::SetMenuFocusable(bool focusable) {
|
|||||||
menu_has_focus_ = focusable;
|
menu_has_focus_ = focusable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewsWindow::EnableView(int id, bool enable) {
|
void ViewsWindow::UpdateToolbarButtonState() {
|
||||||
if (!window_) {
|
SetViewEnabled(window_, ID_BACK_BUTTON, can_go_back_);
|
||||||
return;
|
SetViewEnabled(window_, ID_FORWARD_BUTTON, can_go_forward_);
|
||||||
}
|
SetViewEnabled(window_, ID_RELOAD_BUTTON, !is_loading_);
|
||||||
// Special handling for |location_bar_| which may be an overlay (e.g. not a
|
SetViewEnabled(window_, ID_STOP_BUTTON, is_loading_);
|
||||||
// child of this view).
|
|
||||||
CefRefPtr<CefView> view =
|
|
||||||
id == ID_URL_TEXTFIELD ? location_bar_ : window_->GetViewForID(id);
|
|
||||||
if (view) {
|
|
||||||
view->SetEnabled(enable);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewsWindow::ShowTopControls(bool show) {
|
void ViewsWindow::ShowTopControls(bool show) {
|
||||||
|
@ -239,8 +239,8 @@ class ViewsWindow : public CefBrowserViewDelegate,
|
|||||||
// Control whether the top menu butons are focusable.
|
// Control whether the top menu butons are focusable.
|
||||||
void SetMenuFocusable(bool focusable);
|
void SetMenuFocusable(bool focusable);
|
||||||
|
|
||||||
// Enable or disable a view by |id|.
|
// Update the toolbar button state.
|
||||||
void EnableView(int id, bool enable);
|
void UpdateToolbarButtonState();
|
||||||
|
|
||||||
// Show/hide top controls on the Window.
|
// Show/hide top controls on the Window.
|
||||||
void ShowTopControls(bool show);
|
void ShowTopControls(bool show);
|
||||||
@ -289,6 +289,11 @@ class ViewsWindow : public CefBrowserViewDelegate,
|
|||||||
bool hide_after_fullscreen_exit_ = false;
|
bool hide_after_fullscreen_exit_ = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Current loading state.
|
||||||
|
bool is_loading_ = false;
|
||||||
|
bool can_go_back_ = false;
|
||||||
|
bool can_go_forward_ = false;
|
||||||
|
|
||||||
// Structure representing an extension.
|
// Structure representing an extension.
|
||||||
struct ExtensionInfo {
|
struct ExtensionInfo {
|
||||||
ExtensionInfo(CefRefPtr<CefExtension> extension, CefRefPtr<CefImage> image)
|
ExtensionInfo(CefRefPtr<CefExtension> extension, CefRefPtr<CefImage> image)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user