It's based on general background knowledge of how trademarks work everywhere in the world, with broad details enforced by international treaties. Specific details vary from country to country and sometimes from state to state or city to city (fun fact - trademarks were originally created for bakers, and they only applied within reasonable walking distance of the baker... because without preservatives people generally ate their bread shortly after buying it).
Nobody ever "owns" a trademark. All you're granted is official recognition and registration as a method of dealing with (and preventing) confusion when two competitors use a similar name or logo or iconic design (think coke bottle shape). As long as *your* business is the one customers associate with your trademark, you can use it. If for any reason people stop associating the trademark with your business then the trademark is void.
Kleenex for example had their trademark stripped. And Google is in real danger of having the same happen to them.
Often two businesses will be allowed to use the same (or a similar) trademark, as is the case here. It actually happens all the time especially when a business starts small and grows to be larger. And while it may be allowed initially, that decision can be changed later.
Trademarks are fluid. And the fact that this Brazilian company doesn't seem to really use "iphone" much, while in Apple's case it's one of the most recognisable brands in the world, that means Apple is likely to win this case. It just might take forever to come to a decision.