refactor: inline simple getters, pt . 2 (#41254)

* refactor: inline AutofillPopup::line_count()

refactor: inline AutofillPopup::value_at()

refactor: inline AutofillPopup::label_at()

* refactor: inline NativeWindow::aspect_ratio()

refactor: inline NativeWindow::aspect_ratio_extra_size()

* refactor: inline BrowserProcessImpl::linux_storage_backend()

* refactor: inline ElectronMenuModel::sharing_item()

* refactor: inline Browser::badge_count()

* refactor: inline WebContents::is_guest()

refactor: inline InspectableWebContents::is_guest()

* refactor: inline InspectableWebContents::dev_tool_bounds()

* refactor: inline WebContents::type()
This commit is contained in:
Charles Kerr 2024-02-09 03:29:14 -06:00 committed by GitHub
parent b253d52faf
commit cee51785e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 71 additions and 115 deletions

View file

@ -1681,7 +1681,7 @@ gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) {
.SetMethod("setBadgeCount", .SetMethod("setBadgeCount",
base::BindRepeating(&Browser::SetBadgeCount, browser)) base::BindRepeating(&Browser::SetBadgeCount, browser))
.SetMethod("getBadgeCount", .SetMethod("getBadgeCount",
base::BindRepeating(&Browser::GetBadgeCount, browser)) base::BindRepeating(&Browser::badge_count, browser))
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings) .SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
.SetMethod("setLoginItemSettings", .SetMethod("setLoginItemSettings",
base::BindRepeating(&Browser::SetLoginItemSettings, browser)) base::BindRepeating(&Browser::SetLoginItemSettings, browser))

View file

@ -31,7 +31,7 @@ bool IsEncryptionAvailable() {
return OSCrypt::IsEncryptionAvailable() || return OSCrypt::IsEncryptionAvailable() ||
(use_password_v10 && (use_password_v10 &&
static_cast<BrowserProcessImpl*>(g_browser_process) static_cast<BrowserProcessImpl*>(g_browser_process)
->GetLinuxStorageBackend() == "basic_text"); ->linux_storage_backend() == "basic_text");
#else #else
return OSCrypt::IsEncryptionAvailable(); return OSCrypt::IsEncryptionAvailable();
#endif #endif
@ -46,7 +46,7 @@ std::string GetSelectedLinuxBackend() {
if (!Browser::Get()->is_ready()) if (!Browser::Get()->is_ready())
return "unknown"; return "unknown";
return static_cast<BrowserProcessImpl*>(g_browser_process) return static_cast<BrowserProcessImpl*>(g_browser_process)
->GetLinuxStorageBackend(); ->linux_storage_backend();
} }
#endif #endif

View file

@ -852,7 +852,7 @@ WebContents::WebContents(v8::Isolate* isolate,
session_.Reset(isolate, session.ToV8()); session_.Reset(isolate, session.ToV8());
std::unique_ptr<content::WebContents> web_contents; std::unique_ptr<content::WebContents> web_contents;
if (IsGuest()) { if (is_guest()) {
scoped_refptr<content::SiteInstance> site_instance = scoped_refptr<content::SiteInstance> site_instance =
content::SiteInstance::CreateForURL(session->browser_context(), content::SiteInstance::CreateForURL(session->browser_context(),
GURL("chrome-guest://fake-host")); GURL("chrome-guest://fake-host"));
@ -922,7 +922,7 @@ void WebContents::InitWithSessionAndOptions(
const gin_helper::Dictionary& options) { const gin_helper::Dictionary& options) {
Observe(owned_web_contents.get()); Observe(owned_web_contents.get());
InitWithWebContents(std::move(owned_web_contents), session->browser_context(), InitWithWebContents(std::move(owned_web_contents), session->browser_context(),
IsGuest()); is_guest());
inspectable_web_contents_->GetView()->SetDelegate(this); inspectable_web_contents_->GetView()->SetDelegate(this);
@ -982,7 +982,7 @@ void WebContents::InitWithSessionAndOptions(
SetUserAgent(GetBrowserContext()->GetUserAgent()); SetUserAgent(GetBrowserContext()->GetUserAgent());
if (IsGuest()) { if (is_guest()) {
NativeWindow* owner_window = nullptr; NativeWindow* owner_window = nullptr;
if (embedder_) { if (embedder_) {
// New WebContents's owner_window is the embedder's owner_window. // New WebContents's owner_window is the embedder's owner_window.
@ -1017,7 +1017,7 @@ void WebContents::InitWithExtensionView(v8::Isolate* isolate,
// Allow toggling DevTools for background pages // Allow toggling DevTools for background pages
Observe(web_contents); Observe(web_contents);
InitWithWebContents(std::unique_ptr<content::WebContents>(web_contents), InitWithWebContents(std::unique_ptr<content::WebContents>(web_contents),
GetBrowserContext(), IsGuest()); GetBrowserContext(), is_guest());
inspectable_web_contents_->GetView()->SetDelegate(this); inspectable_web_contents_->GetView()->SetDelegate(this);
} }
#endif #endif
@ -1066,7 +1066,7 @@ WebContents::~WebContents() {
// For guest view based on OOPIF, the WebContents is released by the embedder // For guest view based on OOPIF, the WebContents is released by the embedder
// frame, and we need to clear the reference to the memory. // frame, and we need to clear the reference to the memory.
bool not_owned_by_this = IsGuest() && attached_; bool not_owned_by_this = is_guest() && attached_;
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
// And background pages are owned by extensions::ExtensionHost. // And background pages are owned by extensions::ExtensionHost.
if (type_ == Type::kBackgroundPage) if (type_ == Type::kBackgroundPage)
@ -1096,7 +1096,7 @@ void WebContents::DeleteThisIfAlive() {
void WebContents::Destroy() { void WebContents::Destroy() {
// The content::WebContents should be destroyed asynchronously when possible // The content::WebContents should be destroyed asynchronously when possible
// as user may choose to destroy WebContents during an event of it. // as user may choose to destroy WebContents during an event of it.
if (Browser::Get()->is_shutting_down() || IsGuest()) { if (Browser::Get()->is_shutting_down() || is_guest()) {
DeleteThisIfAlive(); DeleteThisIfAlive();
} else { } else {
content::GetUIThreadTaskRunner({})->PostTask( content::GetUIThreadTaskRunner({})->PostTask(
@ -2155,7 +2155,7 @@ void WebContents::DidFinishNavigation(
Emit("did-navigate", url, http_response_code, http_status_text); Emit("did-navigate", url, http_response_code, http_status_text);
} }
} }
if (IsGuest()) if (is_guest())
Emit("load-commit", url, is_main_frame); Emit("load-commit", url, is_main_frame);
} else { } else {
auto url = navigation_handle->GetURL(); auto url = navigation_handle->GetURL();
@ -2374,10 +2374,6 @@ base::ProcessId WebContents::GetOSProcessID() const {
return base::GetProcId(process_handle); return base::GetProcId(process_handle);
} }
WebContents::Type WebContents::GetType() const {
return type_;
}
bool WebContents::Equal(const WebContents* web_contents) const { bool WebContents::Equal(const WebContents* web_contents) const {
return ID() == web_contents->ID(); return ID() == web_contents->ID();
} }
@ -3371,7 +3367,7 @@ bool WebContents::IsFocused() const {
if (!view) if (!view)
return false; return false;
if (GetType() != Type::kBackgroundPage) { if (type() != Type::kBackgroundPage) {
auto* window = web_contents()->GetNativeView()->GetToplevelWindow(); auto* window = web_contents()->GetNativeView()->GetToplevelWindow();
if (window && !window->IsVisible()) if (window && !window->IsVisible())
return false; return false;
@ -3567,10 +3563,6 @@ void WebContents::OnCursorChanged(const ui::Cursor& cursor) {
} }
} }
bool WebContents::IsGuest() const {
return type_ == Type::kWebView;
}
void WebContents::AttachToIframe(content::WebContents* embedder_web_contents, void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
int embedder_frame_id) { int embedder_frame_id) {
attached_ = true; attached_ = true;
@ -3782,7 +3774,7 @@ void WebContents::SetImageAnimationPolicy(const std::string& new_policy) {
} }
void WebContents::SetBackgroundColor(std::optional<SkColor> maybe_color) { void WebContents::SetBackgroundColor(std::optional<SkColor> maybe_color) {
SkColor color = maybe_color.value_or((IsGuest() && guest_transparent_) || SkColor color = maybe_color.value_or((is_guest() && guest_transparent_) ||
type_ == Type::kBrowserView type_ == Type::kBrowserView
? SK_ColorTRANSPARENT ? SK_ColorTRANSPARENT
: SK_ColorWHITE); : SK_ColorWHITE);
@ -4304,7 +4296,7 @@ void WebContents::UpdateHtmlApiFullscreen(bool fullscreen) {
} }
// Make sure all child webviews quit html fullscreen. // Make sure all child webviews quit html fullscreen.
if (!fullscreen && !IsGuest()) { if (!fullscreen && !is_guest()) {
auto* manager = WebViewManager::GetWebViewManager(web_contents()); auto* manager = WebViewManager::GetWebViewManager(web_contents());
manager->ForEachGuest(web_contents(), [&](content::WebContents* guest) { manager->ForEachGuest(web_contents(), [&](content::WebContents* guest) {
WebContents* api_web_contents = WebContents::From(guest); WebContents* api_web_contents = WebContents::From(guest);
@ -4416,7 +4408,7 @@ void WebContents::FillObjectTemplate(v8::Isolate* isolate,
.SetMethod("getZoomLevel", &WebContents::GetZoomLevel) .SetMethod("getZoomLevel", &WebContents::GetZoomLevel)
.SetMethod("setZoomFactor", &WebContents::SetZoomFactor) .SetMethod("setZoomFactor", &WebContents::SetZoomFactor)
.SetMethod("getZoomFactor", &WebContents::GetZoomFactor) .SetMethod("getZoomFactor", &WebContents::GetZoomFactor)
.SetMethod("getType", &WebContents::GetType) .SetMethod("getType", &WebContents::type)
.SetMethod("_getPreloadPaths", &WebContents::GetPreloadPaths) .SetMethod("_getPreloadPaths", &WebContents::GetPreloadPaths)
.SetMethod("getLastWebPreferences", &WebContents::GetLastWebPreferences) .SetMethod("getLastWebPreferences", &WebContents::GetLastWebPreferences)
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow) .SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)

View file

@ -173,7 +173,7 @@ class WebContents : public ExclusiveAccessContext,
void SetBackgroundThrottling(bool allowed); void SetBackgroundThrottling(bool allowed);
int GetProcessID() const; int GetProcessID() const;
base::ProcessId GetOSProcessID() const; base::ProcessId GetOSProcessID() const;
Type GetType() const; [[nodiscard]] Type type() const { return type_; }
bool Equal(const WebContents* web_contents) const; bool Equal(const WebContents* web_contents) const;
void LoadURL(const GURL& url, const gin_helper::Dictionary& options); void LoadURL(const GURL& url, const gin_helper::Dictionary& options);
void Reload(); void Reload();
@ -292,7 +292,7 @@ class WebContents : public ExclusiveAccessContext,
v8::Local<v8::Promise> CapturePage(gin::Arguments* args); v8::Local<v8::Promise> CapturePage(gin::Arguments* args);
// Methods for creating <webview>. // Methods for creating <webview>.
bool IsGuest() const; [[nodiscard]] bool is_guest() const { return type_ == Type::kWebView; }
void AttachToIframe(content::WebContents* embedder_web_contents, void AttachToIframe(content::WebContents* embedder_web_contents,
int embedder_frame_id); int embedder_frame_id);
void DetachFromOuterFrame(); void DetachFromOuterFrame();

View file

@ -24,7 +24,7 @@ bool WebContents::IsFocused() const {
if (!view) if (!view)
return false; return false;
if (GetType() != Type::kBackgroundPage) { if (type() != Type::kBackgroundPage) {
auto window = [web_contents()->GetNativeView().GetNativeNSView() window]; auto window = [web_contents()->GetNativeView().GetNativeNSView() window];
// On Mac the render widget host view does not lose focus when the window // On Mac the render widget host view does not lose focus when the window
// loses focus so check if the top level window is the key window. // loses focus so check if the top level window is the key window.

View file

@ -159,10 +159,6 @@ void Browser::SetName(const std::string& name) {
OverriddenApplicationName() = name; OverriddenApplicationName() = name;
} }
int Browser::GetBadgeCount() {
return badge_count_;
}
bool Browser::OpenFile(const std::string& file_path) { bool Browser::OpenFile(const std::string& file_path) {
bool prevent_default = false; bool prevent_default = false;
for (BrowserObserver& observer : observers_) for (BrowserObserver& observer : observers_)

View file

@ -110,7 +110,7 @@ class Browser : public WindowListObserver {
// Set/Get the badge count. // Set/Get the badge count.
bool SetBadgeCount(std::optional<int> count); bool SetBadgeCount(std::optional<int> count);
int GetBadgeCount(); [[nodiscard]] int badge_count() const { return badge_count_; }
#if BUILDFLAG(IS_WIN) #if BUILDFLAG(IS_WIN)
struct LaunchItem { struct LaunchItem {

View file

@ -340,10 +340,6 @@ void BrowserProcessImpl::SetLinuxStorageBackend(
break; break;
} }
} }
const std::string& BrowserProcessImpl::GetLinuxStorageBackend() const {
return selected_linux_storage_backend_;
}
#endif // BUILDFLAG(IS_LINUX) #endif // BUILDFLAG(IS_LINUX)
void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) { void BrowserProcessImpl::SetApplicationLocale(const std::string& locale) {

View file

@ -59,7 +59,9 @@ class BrowserProcessImpl : public BrowserProcess {
#if BUILDFLAG(IS_LINUX) #if BUILDFLAG(IS_LINUX)
void SetLinuxStorageBackend(os_crypt::SelectedLinuxBackend selected_backend); void SetLinuxStorageBackend(os_crypt::SelectedLinuxBackend selected_backend);
const std::string& GetLinuxStorageBackend() const; [[nodiscard]] const std::string& linux_storage_backend() const {
return selected_linux_storage_backend_;
}
#endif #endif
void EndSession() override {} void EndSession() override {}

View file

@ -520,14 +520,6 @@ bool NativeWindow::IsMenuBarVisible() const {
return true; return true;
} }
double NativeWindow::GetAspectRatio() const {
return aspect_ratio_;
}
gfx::Size NativeWindow::GetAspectRatioExtraSize() const {
return aspect_ratio_extraSize_;
}
void NativeWindow::SetAspectRatio(double aspect_ratio, void NativeWindow::SetAspectRatio(double aspect_ratio,
const gfx::Size& extra_size) { const gfx::Size& extra_size) {
aspect_ratio_ = aspect_ratio; aspect_ratio_ = aspect_ratio;

View file

@ -264,8 +264,10 @@ class NativeWindow : public base::SupportsUserData,
virtual bool IsMenuBarVisible() const; virtual bool IsMenuBarVisible() const;
// Set the aspect ratio when resizing window. // Set the aspect ratio when resizing window.
double GetAspectRatio() const; [[nodiscard]] double aspect_ratio() const { return aspect_ratio_; }
gfx::Size GetAspectRatioExtraSize() const; [[nodiscard]] gfx::Size aspect_ratio_extra_size() const {
return aspect_ratio_extraSize_;
}
virtual void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size); virtual void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size);
// File preview APIs. // File preview APIs.

View file

@ -641,7 +641,7 @@ bool NativeWindowMac::IsMaximized() const {
if (HasStyleMask(NSWindowStyleMaskResizable) != 0) if (HasStyleMask(NSWindowStyleMaskResizable) != 0)
return [window_ isZoomed]; return [window_ isZoomed];
NSRect rectScreen = GetAspectRatio() > 0.0 NSRect rectScreen = aspect_ratio() > 0.0
? default_frame_for_zoom() ? default_frame_for_zoom()
: [[NSScreen mainScreen] visibleFrame]; : [[NSScreen mainScreen] visibleFrame];

View file

@ -231,7 +231,7 @@ void AutofillPopup::SetItems(const std::vector<std::u16string>& values,
void AutofillPopup::AcceptSuggestion(int index) { void AutofillPopup::AcceptSuggestion(int index) {
mojo::AssociatedRemote<mojom::ElectronAutofillAgent> autofill_agent; mojo::AssociatedRemote<mojom::ElectronAutofillAgent> autofill_agent;
frame_host_->GetRemoteAssociatedInterfaces()->GetInterface(&autofill_agent); frame_host_->GetRemoteAssociatedInterfaces()->GetInterface(&autofill_agent);
autofill_agent->AcceptDataListSuggestion(GetValueAt(index)); autofill_agent->AcceptDataListSuggestion(value_at(index));
} }
void AutofillPopup::UpdatePopupBounds() { void AutofillPopup::UpdatePopupBounds() {
@ -272,11 +272,10 @@ int AutofillPopup::GetDesiredPopupWidth() {
int popup_width = element_bounds_.width(); int popup_width = element_bounds_.width();
for (size_t i = 0; i < values_.size(); ++i) { for (size_t i = 0; i < values_.size(); ++i) {
int row_size = int row_size = kEndPadding + 2 * kPopupBorderThickness +
kEndPadding + 2 * kPopupBorderThickness + gfx::GetStringWidth(value_at(i), GetValueFontListForRow(i)) +
gfx::GetStringWidth(GetValueAt(i), GetValueFontListForRow(i)) + gfx::GetStringWidth(label_at(i), GetLabelFontListForRow(i));
gfx::GetStringWidth(GetLabelAt(i), GetLabelFontListForRow(i)); if (!label_at(i).empty())
if (!GetLabelAt(i).empty())
row_size += kNamePadding + kEndPadding; row_size += kNamePadding + kEndPadding;
popup_width = std::max(popup_width, row_size); popup_width = std::max(popup_width, row_size);
@ -307,18 +306,6 @@ ui::ColorId AutofillPopup::GetBackgroundColorIDForRow(int index) const {
: ui::kColorResultsTableNormalBackground; : ui::kColorResultsTableNormalBackground;
} }
int AutofillPopup::GetLineCount() {
return values_.size();
}
std::u16string AutofillPopup::GetValueAt(int i) {
return values_.at(i);
}
std::u16string AutofillPopup::GetLabelAt(int i) {
return labels_.at(i);
}
int AutofillPopup::LineFromY(int y) const { int AutofillPopup::LineFromY(int y) const {
int current_height = kPopupBorderThickness; int current_height = kPopupBorderThickness;

View file

@ -57,9 +57,9 @@ class AutofillPopup : public views::ViewObserver {
const gfx::FontList& GetLabelFontListForRow(int index) const; const gfx::FontList& GetLabelFontListForRow(int index) const;
ui::ColorId GetBackgroundColorIDForRow(int index) const; ui::ColorId GetBackgroundColorIDForRow(int index) const;
int GetLineCount(); int line_count() const { return values_.size(); }
std::u16string GetValueAt(int i); const std::u16string& value_at(int i) const { return values_.at(i); }
std::u16string GetLabelAt(int i); const std::u16string& label_at(int i) const { return labels_.at(i); }
int LineFromY(int y) const; int LineFromY(int y) const;
int selected_index_; int selected_index_;

View file

@ -27,7 +27,7 @@
devtools_is_first_responder_ = NO; devtools_is_first_responder_ = NO;
attached_to_window_ = NO; attached_to_window_ = NO;
if (inspectableWebContentsView_->inspectable_web_contents()->IsGuest()) { if (inspectableWebContentsView_->inspectable_web_contents()->is_guest()) {
fake_view_ = [[NSView alloc] init]; fake_view_ = [[NSView alloc] init];
[fake_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [fake_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[self addSubview:fake_view_]; [self addSubview:fake_view_];

View file

@ -493,8 +493,8 @@ NSArray* ConvertSharingItemToNS(const SharingItem& item) {
if (menu_) if (menu_)
return menu_; return menu_;
if (model_ && model_->GetSharingItem()) { if (model_ && model_->sharing_item()) {
NSMenu* menu = [self createShareMenuForItem:*model_->GetSharingItem()]; NSMenu* menu = [self createShareMenuForItem:*model_->sharing_item()];
menu_ = menu; menu_ = menu;
} else { } else {
menu_ = [[NSMenu alloc] initWithTitle:@""]; menu_ = [[NSMenu alloc] initWithTitle:@""];

View file

@ -76,7 +76,7 @@ using FullScreenTransitionState =
- (NSRect)windowWillUseStandardFrame:(NSWindow*)window - (NSRect)windowWillUseStandardFrame:(NSWindow*)window
defaultFrame:(NSRect)frame { defaultFrame:(NSRect)frame {
if (!shell_->zoom_to_page_width()) { if (!shell_->zoom_to_page_width()) {
if (shell_->GetAspectRatio() > 0.0) if (shell_->aspect_ratio() > 0.0)
shell_->set_default_frame_for_zoom(frame); shell_->set_default_frame_for_zoom(frame);
return frame; return frame;
} }
@ -104,7 +104,7 @@ using FullScreenTransitionState =
// Set the width. Don't touch y or height. // Set the width. Don't touch y or height.
frame.size.width = zoomed_width; frame.size.width = zoomed_width;
if (shell_->GetAspectRatio() > 0.0) if (shell_->aspect_ratio() > 0.0)
shell_->set_default_frame_for_zoom(frame); shell_->set_default_frame_for_zoom(frame);
return frame; return frame;
@ -139,13 +139,12 @@ using FullScreenTransitionState =
- (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize { - (NSSize)windowWillResize:(NSWindow*)sender toSize:(NSSize)frameSize {
NSSize newSize = frameSize; NSSize newSize = frameSize;
double aspectRatio = shell_->GetAspectRatio();
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow(); NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
if (aspectRatio > 0.0) { if (const double aspectRatio = shell_->aspect_ratio(); aspectRatio > 0.0) {
gfx::Size windowSize = shell_->GetSize(); const gfx::Size windowSize = shell_->GetSize();
gfx::Size contentSize = shell_->GetContentSize(); const gfx::Size contentSize = shell_->GetContentSize();
gfx::Size extraSize = shell_->GetAspectRatioExtraSize(); const gfx::Size extraSize = shell_->aspect_ratio_extra_size();
double titleBarHeight = windowSize.height() - contentSize.height(); double titleBarHeight = windowSize.height() - contentSize.height();
double extraWidthPlusFrame = double extraWidthPlusFrame =

View file

@ -99,11 +99,6 @@ bool ElectronMenuModel::GetSharingItemAt(size_t index,
void ElectronMenuModel::SetSharingItem(SharingItem item) { void ElectronMenuModel::SetSharingItem(SharingItem item) {
sharing_item_.emplace(std::move(item)); sharing_item_.emplace(std::move(item));
} }
const std::optional<ElectronMenuModel::SharingItem>&
ElectronMenuModel::GetSharingItem() const {
return sharing_item_;
}
#endif #endif
void ElectronMenuModel::MenuWillClose() { void ElectronMenuModel::MenuWillClose() {

View file

@ -98,7 +98,10 @@ class ElectronMenuModel : public ui::SimpleMenuModel {
bool GetSharingItemAt(size_t index, SharingItem* item) const; bool GetSharingItemAt(size_t index, SharingItem* item) const;
// Set/Get the SharingItem of this menu. // Set/Get the SharingItem of this menu.
void SetSharingItem(SharingItem item); void SetSharingItem(SharingItem item);
const std::optional<SharingItem>& GetSharingItem() const; [[nodiscard]] const std::optional<SharingItem>& sharing_item() const {
return sharing_item_;
}
#endif #endif
// ui::SimpleMenuModel: // ui::SimpleMenuModel:

View file

@ -384,10 +384,6 @@ InspectableWebContentsDelegate* InspectableWebContents::GetDelegate() const {
return delegate_; return delegate_;
} }
bool InspectableWebContents::IsGuest() const {
return is_guest_;
}
void InspectableWebContents::ReleaseWebContents() { void InspectableWebContents::ReleaseWebContents() {
web_contents_.release(); web_contents_.release();
WebContentsDestroyed(); WebContentsDestroyed();
@ -454,7 +450,7 @@ void InspectableWebContents::CloseDevTools() {
managed_devtools_web_contents_.reset(); managed_devtools_web_contents_.reset();
} }
embedder_message_dispatcher_.reset(); embedder_message_dispatcher_.reset();
if (!IsGuest()) if (!is_guest())
web_contents_->Focus(); web_contents_->Focus();
} }
} }
@ -516,10 +512,6 @@ void InspectableWebContents::CallClientFunction(
std::move(arguments), std::move(cb)); std::move(arguments), std::move(cb));
} }
gfx::Rect InspectableWebContents::GetDevToolsBounds() const {
return devtools_bounds_;
}
void InspectableWebContents::SaveDevToolsBounds(const gfx::Rect& bounds) { void InspectableWebContents::SaveDevToolsBounds(const gfx::Rect& bounds) {
pref_service_->Set(kDevToolsBoundsPref, pref_service_->Set(kDevToolsBoundsPref,
base::Value{RectToDictionary(bounds)}); base::Value{RectToDictionary(bounds)});

View file

@ -55,7 +55,7 @@ class InspectableWebContents
void SetDelegate(InspectableWebContentsDelegate* delegate); void SetDelegate(InspectableWebContentsDelegate* delegate);
InspectableWebContentsDelegate* GetDelegate() const; InspectableWebContentsDelegate* GetDelegate() const;
bool IsGuest() const; [[nodiscard]] bool is_guest() const { return is_guest_; }
void ReleaseWebContents(); void ReleaseWebContents();
void SetDevToolsWebContents(content::WebContents* devtools); void SetDevToolsWebContents(content::WebContents* devtools);
void SetDockState(const std::string& state); void SetDockState(const std::string& state);
@ -76,7 +76,9 @@ class InspectableWebContents
void InspectElement(int x, int y); void InspectElement(int x, int y);
// Return the last position and size of devtools window. // Return the last position and size of devtools window.
gfx::Rect GetDevToolsBounds() const; [[nodiscard]] const gfx::Rect& dev_tools_bounds() const {
return devtools_bounds_;
}
void SaveDevToolsBounds(const gfx::Rect& bounds); void SaveDevToolsBounds(const gfx::Rect& bounds);
// Return the last set zoom level of devtools window. // Return the last set zoom level of devtools window.

View file

@ -124,7 +124,7 @@ void AutofillPopupView::OnSuggestionsChanged() {
return; return;
CreateChildViews(); CreateChildViews();
if (popup_->GetLineCount() == 0) { if (popup_->line_count() == 0) {
popup_->Hide(); popup_->Hide();
return; return;
} }
@ -177,28 +177,28 @@ void AutofillPopupView::DrawAutofillEntry(gfx::Canvas* canvas,
int x_align_left = value_rect.x(); int x_align_left = value_rect.x();
const int value_width = gfx::GetStringWidth( const int value_width = gfx::GetStringWidth(
popup_->GetValueAt(index), popup_->GetValueFontListForRow(index)); popup_->value_at(index), popup_->GetValueFontListForRow(index));
int value_x_align_left = x_align_left; int value_x_align_left = x_align_left;
value_x_align_left = value_x_align_left =
is_rtl ? value_rect.right() - value_width : value_rect.x(); is_rtl ? value_rect.right() - value_width : value_rect.x();
canvas->DrawStringRectWithFlags( canvas->DrawStringRectWithFlags(
popup_->GetValueAt(index), popup_->GetValueFontListForRow(index), popup_->value_at(index), popup_->GetValueFontListForRow(index),
GetColorProvider()->GetColor(ui::kColorResultsTableNormalText), GetColorProvider()->GetColor(ui::kColorResultsTableNormalText),
gfx::Rect(value_x_align_left, value_rect.y(), value_width, gfx::Rect(value_x_align_left, value_rect.y(), value_width,
value_rect.height()), value_rect.height()),
text_align); text_align);
// Draw the label text, if one exists. // Draw the label text, if one exists.
if (!popup_->GetLabelAt(index).empty()) { if (auto const& label = popup_->label_at(index); !label.empty()) {
const int label_width = gfx::GetStringWidth( const int label_width =
popup_->GetLabelAt(index), popup_->GetLabelFontListForRow(index)); gfx::GetStringWidth(label, popup_->GetLabelFontListForRow(index));
int label_x_align_left = x_align_left; int label_x_align_left = x_align_left;
label_x_align_left = label_x_align_left =
is_rtl ? value_rect.x() : value_rect.right() - label_width; is_rtl ? value_rect.x() : value_rect.right() - label_width;
canvas->DrawStringRectWithFlags( canvas->DrawStringRectWithFlags(
popup_->GetLabelAt(index), popup_->GetLabelFontListForRow(index), label, popup_->GetLabelFontListForRow(index),
GetColorProvider()->GetColor(ui::kColorResultsTableDimmedText), GetColorProvider()->GetColor(ui::kColorResultsTableDimmedText),
gfx::Rect(label_x_align_left, entry_rect.y(), label_width, gfx::Rect(label_x_align_left, entry_rect.y(), label_width,
entry_rect.height()), entry_rect.height()),
@ -212,8 +212,8 @@ void AutofillPopupView::CreateChildViews() {
RemoveAllChildViews(); RemoveAllChildViews();
for (int i = 0; i < popup_->GetLineCount(); ++i) { for (int i = 0; i < popup_->line_count(); ++i) {
auto* child_view = new AutofillPopupChildView(popup_->GetValueAt(i)); auto* child_view = new AutofillPopupChildView(popup_->value_at(i));
child_view->set_drag_controller(this); child_view->set_drag_controller(this);
AddChildView(child_view); AddChildView(child_view);
} }
@ -234,8 +234,7 @@ void AutofillPopupView::DoUpdateBoundsAndRedrawPopup() {
} }
void AutofillPopupView::OnPaint(gfx::Canvas* canvas) { void AutofillPopupView::OnPaint(gfx::Canvas* canvas) {
if (!popup_ || if (!popup_ || static_cast<size_t>(popup_->line_count()) != children().size())
static_cast<size_t>(popup_->GetLineCount()) != children().size())
return; return;
gfx::Canvas* draw_canvas = canvas; gfx::Canvas* draw_canvas = canvas;
SkBitmap bitmap; SkBitmap bitmap;
@ -252,7 +251,7 @@ void AutofillPopupView::OnPaint(gfx::Canvas* canvas) {
GetColorProvider()->GetColor(ui::kColorResultsTableNormalBackground)); GetColorProvider()->GetColor(ui::kColorResultsTableNormalBackground));
OnPaintBorder(draw_canvas); OnPaintBorder(draw_canvas);
for (int i = 0; i < popup_->GetLineCount(); ++i) { for (int i = 0; i < popup_->line_count(); ++i) {
gfx::Rect line_rect = popup_->GetRowBounds(i); gfx::Rect line_rect = popup_->GetRowBounds(i);
DrawAutofillEntry(draw_canvas, i, line_rect); DrawAutofillEntry(draw_canvas, i, line_rect);
@ -381,7 +380,7 @@ bool AutofillPopupView::HandleKeyPressEvent(
SetSelectedLine(0); SetSelectedLine(0);
return true; return true;
case ui::VKEY_NEXT: // Page down. case ui::VKEY_NEXT: // Page down.
SetSelectedLine(popup_->GetLineCount() - 1); SetSelectedLine(popup_->line_count() - 1);
return true; return true;
case ui::VKEY_ESCAPE: case ui::VKEY_ESCAPE:
popup_->Hide(); popup_->Hide();
@ -421,7 +420,7 @@ void AutofillPopupView::AcceptSuggestion(int index) {
} }
bool AutofillPopupView::AcceptSelectedLine() { bool AutofillPopupView::AcceptSelectedLine() {
if (!selected_line_ || selected_line_.value() >= popup_->GetLineCount()) if (!selected_line_ || selected_line_.value() >= popup_->line_count())
return false; return false;
AcceptSuggestion(selected_line_.value()); AcceptSuggestion(selected_line_.value());
@ -441,7 +440,7 @@ void AutofillPopupView::SetSelectedLine(std::optional<int> selected_line) {
return; return;
if (selected_line_ == selected_line) if (selected_line_ == selected_line)
return; return;
if (selected_line && selected_line.value() >= popup_->GetLineCount()) if (selected_line && selected_line.value() >= popup_->line_count())
return; return;
auto previous_selected_line(selected_line_); auto previous_selected_line(selected_line_);
@ -461,7 +460,7 @@ void AutofillPopupView::SelectNextLine() {
return; return;
int new_selected_line = selected_line_ ? *selected_line_ + 1 : 0; int new_selected_line = selected_line_ ? *selected_line_ + 1 : 0;
if (new_selected_line >= popup_->GetLineCount()) if (new_selected_line >= popup_->line_count())
new_selected_line = 0; new_selected_line = 0;
SetSelectedLine(new_selected_line); SetSelectedLine(new_selected_line);
@ -473,7 +472,7 @@ void AutofillPopupView::SelectPreviousLine() {
int new_selected_line = selected_line_.value_or(0) - 1; int new_selected_line = selected_line_.value_or(0) - 1;
if (new_selected_line < 0) if (new_selected_line < 0)
new_selected_line = popup_->GetLineCount() - 1; new_selected_line = popup_->line_count() - 1;
SetSelectedLine(new_selected_line); SetSelectedLine(new_selected_line);
} }

View file

@ -83,7 +83,7 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews(
: InspectableWebContentsView(inspectable_web_contents), : InspectableWebContentsView(inspectable_web_contents),
devtools_web_view_(new views::WebView(nullptr)), devtools_web_view_(new views::WebView(nullptr)),
title_(u"Developer Tools") { title_(u"Developer Tools") {
if (!inspectable_web_contents_->IsGuest() && if (!inspectable_web_contents_->is_guest() &&
inspectable_web_contents_->GetWebContents()->GetNativeView()) { inspectable_web_contents_->GetWebContents()->GetNativeView()) {
auto* contents_web_view = new views::WebView(nullptr); auto* contents_web_view = new views::WebView(nullptr);
contents_web_view->SetWebContents( contents_web_view->SetWebContents(
@ -116,8 +116,7 @@ void InspectableWebContentsViewViews::ShowDevTools(bool activate) {
if (devtools_window_) { if (devtools_window_) {
devtools_window_web_view_->SetWebContents( devtools_window_web_view_->SetWebContents(
inspectable_web_contents_->GetDevToolsWebContents()); inspectable_web_contents_->GetDevToolsWebContents());
devtools_window_->SetBounds( devtools_window_->SetBounds(inspectable_web_contents()->dev_tools_bounds());
inspectable_web_contents()->GetDevToolsBounds());
if (activate) { if (activate) {
devtools_window_->Show(); devtools_window_->Show();
} else { } else {
@ -182,7 +181,7 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked, bool activate) {
views::Widget::InitParams params; views::Widget::InitParams params;
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params.delegate = devtools_window_delegate_; params.delegate = devtools_window_delegate_;
params.bounds = inspectable_web_contents()->GetDevToolsBounds(); params.bounds = inspectable_web_contents()->dev_tools_bounds();
#if BUILDFLAG(IS_LINUX) #if BUILDFLAG(IS_LINUX)
params.wm_role_name = "devtools"; params.wm_role_name = "devtools";