Commit 98cb52ed authored by k.czech's avatar k.czech Committed by Commit bot

Possible deferencing from nullptrs in AtkComponent interface.

Make sure AtkComponent interface callbacks operate on valid pointers.
GetExtent and GetPosition are almost the same. Reducing some code
by adding helper method SetExtentsRelativeToAtkCoordinateType.

BUG=463671

Review URL: https://codereview.chromium.org/1129813004

Cr-Commit-Position: refs/heads/master@{#329664}
parent 90acb0f2
...@@ -204,7 +204,17 @@ static void ax_platform_node_auralinux_get_extents(AtkComponent* atk_component, ...@@ -204,7 +204,17 @@ static void ax_platform_node_auralinux_get_extents(AtkComponent* atk_component,
gint* x, gint* y, gint* x, gint* y,
gint* width, gint* height, gint* width, gint* height,
AtkCoordType coord_type) { AtkCoordType coord_type) {
*x = *y = *width = *height = 0; g_return_if_fail(ATK_IS_COMPONENT(atk_component));
if (x)
*x = 0;
if (y)
*y = 0;
if (width)
*width = 0;
if (height)
*height = 0;
AtkObject* atk_object = ATK_OBJECT(atk_component); AtkObject* atk_object = ATK_OBJECT(atk_component);
ui::AXPlatformNodeAuraLinux* obj = ui::AXPlatformNodeAuraLinux* obj =
AtkObjectToAXPlatformNodeAuraLinux(atk_object); AtkObjectToAXPlatformNodeAuraLinux(atk_object);
...@@ -217,7 +227,13 @@ static void ax_platform_node_auralinux_get_extents(AtkComponent* atk_component, ...@@ -217,7 +227,13 @@ static void ax_platform_node_auralinux_get_extents(AtkComponent* atk_component,
static void ax_platform_node_auralinux_get_position(AtkComponent* atk_component, static void ax_platform_node_auralinux_get_position(AtkComponent* atk_component,
gint* x, gint* y, gint* x, gint* y,
AtkCoordType coord_type) { AtkCoordType coord_type) {
*x = *y = 0; g_return_if_fail(ATK_IS_COMPONENT(atk_component));
if (x)
*x = 0;
if (y)
*y = 0;
AtkObject* atk_object = ATK_OBJECT(atk_component); AtkObject* atk_object = ATK_OBJECT(atk_component);
ui::AXPlatformNodeAuraLinux* obj = ui::AXPlatformNodeAuraLinux* obj =
AtkObjectToAXPlatformNodeAuraLinux(atk_object); AtkObjectToAXPlatformNodeAuraLinux(atk_object);
...@@ -229,7 +245,13 @@ static void ax_platform_node_auralinux_get_position(AtkComponent* atk_component, ...@@ -229,7 +245,13 @@ static void ax_platform_node_auralinux_get_position(AtkComponent* atk_component,
static void ax_platform_node_auralinux_get_size(AtkComponent* atk_component, static void ax_platform_node_auralinux_get_size(AtkComponent* atk_component,
gint* width, gint* height) { gint* width, gint* height) {
*width = *height = 0; g_return_if_fail(ATK_IS_COMPONENT(atk_component));
if (width)
*width = 0;
if (height)
*height = 0;
AtkObject* atk_object = ATK_OBJECT(atk_component); AtkObject* atk_object = ATK_OBJECT(atk_component);
ui::AXPlatformNodeAuraLinux* obj = ui::AXPlatformNodeAuraLinux* obj =
AtkObjectToAXPlatformNodeAuraLinux(atk_object); AtkObjectToAXPlatformNodeAuraLinux(atk_object);
...@@ -465,43 +487,50 @@ int AXPlatformNodeAuraLinux::GetIndexInParent() { ...@@ -465,43 +487,50 @@ int AXPlatformNodeAuraLinux::GetIndexInParent() {
return 0; return 0;
} }
void AXPlatformNodeAuraLinux::GetExtents(gint* x, gint* y, void AXPlatformNodeAuraLinux::SetExtentsRelativeToAtkCoordinateType(
gint* width, gint* height, gint* x, gint* y, gint* width, gint* height, AtkCoordType coord_type) {
AtkCoordType coord_type) {
gfx::Rect extents = GetBoundsInScreen(); gfx::Rect extents = GetBoundsInScreen();
*x = extents.x(); if (x)
*y = extents.y(); *x = extents.x();
*width = extents.width(); if (y)
*height = extents.height(); *y = extents.y();
if (width)
*width = extents.width();
if (height)
*height = extents.height();
if (coord_type == ATK_XY_WINDOW) { if (coord_type == ATK_XY_WINDOW) {
AtkObject* atk_object = GetParent(); AtkObject* atk_object = GetParent();
gfx::Point window_coords = FindAtkObjectParentCoords(atk_object); gfx::Point window_coords = FindAtkObjectParentCoords(atk_object);
*x -= window_coords.x(); if (x)
*y -= window_coords.y(); *x -= window_coords.x();
if (y)
*y -= window_coords.y();
} }
} }
void AXPlatformNodeAuraLinux::GetExtents(gint* x, gint* y,
gint* width, gint* height,
AtkCoordType coord_type) {
SetExtentsRelativeToAtkCoordinateType(x, y,
width, height,
coord_type);
}
void AXPlatformNodeAuraLinux::GetPosition(gint* x, gint* y, void AXPlatformNodeAuraLinux::GetPosition(gint* x, gint* y,
AtkCoordType coord_type) { AtkCoordType coord_type) {
gfx::Rect rect_pos = GetBoundsInScreen(); SetExtentsRelativeToAtkCoordinateType(x, y,
nullptr,nullptr,
*x = rect_pos.x(); coord_type);
*y = rect_pos.y();
if (coord_type == ATK_XY_WINDOW) {
AtkObject* atk_object = GetParent();
gfx::Point window_coords = FindAtkObjectParentCoords(atk_object);
*x -= window_coords.x();
*y -= window_coords.y();
}
} }
void AXPlatformNodeAuraLinux::GetSize(gint* width, gint* height) { void AXPlatformNodeAuraLinux::GetSize(gint* width, gint* height) {
gfx::Rect rect_size = GetData().location; gfx::Rect rect_size = GetData().location;
*width = rect_size.width(); if (width)
*height = rect_size.height(); *width = rect_size.width();
if (height)
*height = rect_size.height();
} }
} // namespace ui } // namespace ui
...@@ -39,6 +39,10 @@ class AXPlatformNodeAuraLinux : public AXPlatformNodeBase { ...@@ -39,6 +39,10 @@ class AXPlatformNodeAuraLinux : public AXPlatformNodeBase {
void GetPosition(gint* x, gint* y, AtkCoordType coord_type); void GetPosition(gint* x, gint* y, AtkCoordType coord_type);
void GetSize(gint* width, gint* height); void GetSize(gint* width, gint* height);
void SetExtentsRelativeToAtkCoordinateType(
gint* x, gint* y, gint* width, gint* height,
AtkCoordType coord_type);
// AXPlatformNode overrides. // AXPlatformNode overrides.
void Destroy() override; void Destroy() override;
gfx::NativeViewAccessible GetNativeViewAccessible() override; gfx::NativeViewAccessible GetNativeViewAccessible() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment